|
|
|
|
@@ -319,7 +319,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
|
|
|
|
|
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d) returning new sock=%d addr=", s, newsock));
|
|
|
|
|
ip_addr_debug_print(SOCKETS_DEBUG, &naddr);
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u\n", port));
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F"\n", port));
|
|
|
|
|
|
|
|
|
|
sock_set_errno(sock, 0);
|
|
|
|
|
return newsock;
|
|
|
|
|
@@ -346,7 +346,7 @@ lwip_bind(int s, const struct sockaddr *name, socklen_t namelen)
|
|
|
|
|
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d, addr=", s));
|
|
|
|
|
ip_addr_debug_print(SOCKETS_DEBUG, &local_addr);
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u)\n", ntohs(local_port)));
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", ntohs(local_port)));
|
|
|
|
|
|
|
|
|
|
err = netconn_bind(sock->conn, &local_addr, ntohs(local_port));
|
|
|
|
|
|
|
|
|
|
@@ -413,7 +413,7 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen)
|
|
|
|
|
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, addr=", s));
|
|
|
|
|
ip_addr_debug_print(SOCKETS_DEBUG, &remote_addr);
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u)\n", ntohs(remote_port)));
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", ntohs(remote_port)));
|
|
|
|
|
|
|
|
|
|
err = netconn_connect(sock->conn, &remote_addr, ntohs(remote_port));
|
|
|
|
|
}
|
|
|
|
|
@@ -480,7 +480,7 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
|
|
|
|
|
u16_t port;
|
|
|
|
|
u8_t done = 0;
|
|
|
|
|
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d, %p, %d, 0x%x, ..)\n", s, mem, len, flags));
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d, %#p, %"SZT_F", 0x%x, ..)\n", s, mem, len, flags));
|
|
|
|
|
sock = get_socket(s);
|
|
|
|
|
if (!sock)
|
|
|
|
|
return -1;
|
|
|
|
|
@@ -506,13 +506,15 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
|
|
|
|
|
if (!buf) {
|
|
|
|
|
/* We should really do some error checking here. */
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): buf == NULL!\n", s));
|
|
|
|
|
sock_set_errno(sock, (((sock->conn->pcb.ip!=NULL) && (sock->conn->err==ERR_OK))?ETIMEDOUT:err_to_errno(sock->conn->err)));
|
|
|
|
|
sock_set_errno(sock, (((sock->conn->pcb.ip != NULL) && (sock->conn->err == ERR_OK))
|
|
|
|
|
? ETIMEDOUT : err_to_errno(sock->conn->err)));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buflen = netbuf_len(buf);
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom: buflen=%d len=%d off=%d sock->lastoffset=%d\n", buflen, len, off, sock->lastoffset));
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom: buflen=%"U16_F" len=%"SZT_F" off=%"U16_F" sock->lastoffset=%"U16_F"\n",
|
|
|
|
|
buflen, len, off, sock->lastoffset));
|
|
|
|
|
|
|
|
|
|
buflen -= sock->lastoffset;
|
|
|
|
|
|
|
|
|
|
@@ -565,7 +567,7 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
|
|
|
|
|
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): addr=", s));
|
|
|
|
|
ip_addr_debug_print(SOCKETS_DEBUG, addr);
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u len=%u\n", port, off));
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F" len=%"U16_F"\n", port, off));
|
|
|
|
|
} else {
|
|
|
|
|
#if SOCKETS_DEBUG
|
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
|
@@ -580,7 +582,7 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
|
|
|
|
|
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): addr=", s));
|
|
|
|
|
ip_addr_debug_print(SOCKETS_DEBUG, addr);
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u len=%u\n", port, off));
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F" len=%"U16_F"\n", port, off));
|
|
|
|
|
#endif /* SOCKETS_DEBUG */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -625,7 +627,7 @@ lwip_send(int s, const void *data, size_t size, int flags)
|
|
|
|
|
struct lwip_socket *sock;
|
|
|
|
|
err_t err;
|
|
|
|
|
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d, data=%p, size=%d, flags=0x%x)\n",
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d, data=%p, size=%"SZT_F", flags=0x%x)\n",
|
|
|
|
|
s, data, size, flags));
|
|
|
|
|
|
|
|
|
|
sock = get_socket(s);
|
|
|
|
|
@@ -643,7 +645,7 @@ lwip_send(int s, const void *data, size_t size, int flags)
|
|
|
|
|
|
|
|
|
|
err = netconn_write(sock->conn, data, size, NETCONN_COPY | ((flags & MSG_MORE)?NETCONN_MORE:0));
|
|
|
|
|
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) err=%d size=%d\n", s, err, size));
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) err=%d size=%"SZT_F"\n", s, err, size));
|
|
|
|
|
sock_set_errno(sock, err_to_errno(err));
|
|
|
|
|
return (err == ERR_OK ? (int)size : -1);
|
|
|
|
|
}
|
|
|
|
|
@@ -720,10 +722,10 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
|
|
|
|
|
buf.port = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, short_size=%d, flags=0x%x to=",
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, short_size=%d"U16_F", flags=0x%x to=",
|
|
|
|
|
s, data, short_size, flags));
|
|
|
|
|
ip_addr_debug_print(SOCKETS_DEBUG, &remote_addr);
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u\n", remote_port));
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F"\n", remote_port));
|
|
|
|
|
|
|
|
|
|
/* make the buffer point to the data that should be sent */
|
|
|
|
|
if ((err = netbuf_ref(&buf, data, short_size)) == ERR_OK) {
|
|
|
|
|
@@ -870,7 +872,8 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
|
|
|
|
|
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select(%d, %p, %p, %p, tvsec=%ld tvusec=%ld)\n",
|
|
|
|
|
maxfdp1, (void *)readset, (void *) writeset, (void *) exceptset,
|
|
|
|
|
timeout ? timeout->tv_sec : -1L, timeout ? timeout->tv_usec : -1L));
|
|
|
|
|
timeout ? (long)timeout->tv_sec : (long)-1,
|
|
|
|
|
timeout ? (long)timeout->tv_usec : (long)-1));
|
|
|
|
|
|
|
|
|
|
select_cb.next = 0;
|
|
|
|
|
select_cb.readset = readset;
|
|
|
|
|
@@ -1127,7 +1130,7 @@ lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local)
|
|
|
|
|
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getaddrname(%d, addr=", s));
|
|
|
|
|
ip_addr_debug_print(SOCKETS_DEBUG, &naddr);
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%d)\n", sin.sin_port));
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", sin.sin_port));
|
|
|
|
|
|
|
|
|
|
sin.sin_port = htons(sin.sin_port);
|
|
|
|
|
sin.sin_addr.s_addr = naddr.addr;
|
|
|
|
|
@@ -1452,7 +1455,7 @@ lwip_getsockopt_internal(void *arg)
|
|
|
|
|
break;
|
|
|
|
|
case IP_MULTICAST_IF:
|
|
|
|
|
((struct in_addr*) optval)->s_addr = sock->conn->pcb.udp->multicast_ip.addr;
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_MULTICAST_IF) = 0x%x\n",
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_MULTICAST_IF) = 0x%"X32_F"\n",
|
|
|
|
|
s, *(u32_t *)optval));
|
|
|
|
|
break;
|
|
|
|
|
#endif /* LWIP_IGMP */
|
|
|
|
|
@@ -1785,12 +1788,12 @@ lwip_setsockopt_internal(void *arg)
|
|
|
|
|
switch (optname) {
|
|
|
|
|
case IP_TTL:
|
|
|
|
|
sock->conn->pcb.ip->ttl = (u8_t)(*(int*)optval);
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TTL, ..) -> %u\n",
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TTL, ..) -> %d\n",
|
|
|
|
|
s, sock->conn->pcb.ip->ttl));
|
|
|
|
|
break;
|
|
|
|
|
case IP_TOS:
|
|
|
|
|
sock->conn->pcb.ip->tos = (u8_t)(*(int*)optval);
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TOS, ..)-> %u\n",
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TOS, ..)-> %d\n",
|
|
|
|
|
s, sock->conn->pcb.ip->tos));
|
|
|
|
|
break;
|
|
|
|
|
#if LWIP_IGMP
|
|
|
|
|
@@ -1834,24 +1837,24 @@ lwip_setsockopt_internal(void *arg)
|
|
|
|
|
break;
|
|
|
|
|
case TCP_KEEPALIVE:
|
|
|
|
|
sock->conn->pcb.tcp->keep_idle = (u32_t)(*(int*)optval);
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPALIVE) -> %lu\n",
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPALIVE) -> %"U32_F"\n",
|
|
|
|
|
s, sock->conn->pcb.tcp->keep_idle));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
#if LWIP_TCP_KEEPALIVE
|
|
|
|
|
case TCP_KEEPIDLE:
|
|
|
|
|
sock->conn->pcb.tcp->keep_idle = 1000*(u32_t)(*(int*)optval);
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPIDLE) -> %lu\n",
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPIDLE) -> %"U32_F"\n",
|
|
|
|
|
s, sock->conn->pcb.tcp->keep_idle));
|
|
|
|
|
break;
|
|
|
|
|
case TCP_KEEPINTVL:
|
|
|
|
|
sock->conn->pcb.tcp->keep_intvl = 1000*(u32_t)(*(int*)optval);
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPINTVL) -> %lu\n",
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPINTVL) -> %"U32_F"\n",
|
|
|
|
|
s, sock->conn->pcb.tcp->keep_intvl));
|
|
|
|
|
break;
|
|
|
|
|
case TCP_KEEPCNT:
|
|
|
|
|
sock->conn->pcb.tcp->keep_cnt = (u32_t)(*(int*)optval);
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPCNT) -> %lu\n",
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPCNT) -> %"U32_F"\n",
|
|
|
|
|
s, sock->conn->pcb.tcp->keep_cnt));
|
|
|
|
|
break;
|
|
|
|
|
#endif /* LWIP_TCP_KEEPALIVE */
|
|
|
|
|
@@ -1916,7 +1919,7 @@ lwip_ioctl(int s, long cmd, void *argp)
|
|
|
|
|
*((u16_t*)argp) += buflen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, FIONREAD, %p) = %u\n", s, argp, *((u16_t*)argp)));
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, FIONREAD, %p) = %"U16_F"\n", s, argp, *((u16_t*)argp)));
|
|
|
|
|
sock_set_errno(sock, 0);
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|