Broke some (too long) lines down to multiple lines, made the file fit our coding standards

This commit is contained in:
goldsimon 2007-05-22 20:30:30 +00:00
parent 78201c0146
commit 2442b985bf

View File

@ -232,7 +232,8 @@ lwip_bind(int s, struct sockaddr *name, socklen_t namelen)
if (!sock) if (!sock)
return -1; return -1;
LWIP_ASSERT("lwip_bind: invalid address", (namelen == sizeof(struct sockaddr_in)) && ((((struct sockaddr_in *)name)->sin_family) == AF_INET)); LWIP_ASSERT("lwip_bind: invalid address", (namelen == sizeof(struct sockaddr_in)) &&
((((struct sockaddr_in *)name)->sin_family) == AF_INET));
local_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr; local_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr;
local_port = ((struct sockaddr_in *)name)->sin_port; local_port = ((struct sockaddr_in *)name)->sin_port;
@ -292,7 +293,8 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen)
if (!sock) if (!sock)
return -1; return -1;
LWIP_ASSERT("lwip_connect: invalid address", (namelen == sizeof(struct sockaddr_in)) && ((((struct sockaddr_in *)name)->sin_family) == AF_INET)); LWIP_ASSERT("lwip_connect: invalid address", (namelen == sizeof(struct sockaddr_in)) &&
((((struct sockaddr_in *)name)->sin_family) == AF_INET));
if (((struct sockaddr_in *)name)->sin_family == AF_UNSPEC) { if (((struct sockaddr_in *)name)->sin_family == AF_UNSPEC) {
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, AF_UNSPEC)\n", s)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, AF_UNSPEC)\n", s));
@ -468,7 +470,8 @@ lwip_send(int s, const void *data, int size, unsigned int flags)
struct lwip_socket *sock; struct lwip_socket *sock;
err_t err; err_t err;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d, data=%p, size=%d, flags=0x%x)\n", s, data, size, flags)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d, data=%p, size=%d, flags=0x%x)\n",
s, data, size, flags));
sock = get_socket(s); sock = get_socket(s);
if (!sock) if (!sock)
@ -511,7 +514,9 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags,
return -1; return -1;
#endif /* LWIP_TCP */ #endif /* LWIP_TCP */
LWIP_ASSERT("lwip_sendto: invalid address", (((to==NULL) && (tolen==0)) || ((tolen == sizeof(struct sockaddr_in)) && ((((struct sockaddr_in *)to)->sin_family) == AF_INET))) ); LWIP_ASSERT("lwip_sendto: invalid address", (((to==NULL) && (tolen==0)) ||
((tolen == sizeof(struct sockaddr_in)) &&
((((struct sockaddr_in *)to)->sin_family) == AF_INET))));
/* initialize a buffer */ /* initialize a buffer */
buf.p = buf.ptr = NULL; buf.p = buf.ptr = NULL;
@ -527,7 +532,8 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags,
buf.port = 0; buf.port = 0;
} }
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, size=%d, flags=0x%x to=", s, data, size, flags)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, size=%d, flags=0x%x to=",
s, data, size, flags));
ip_addr_debug_print(SOCKETS_DEBUG, &remote_addr); ip_addr_debug_print(SOCKETS_DEBUG, &remote_addr);
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u\n", remote_port)); LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u\n", remote_port));
@ -556,18 +562,22 @@ lwip_socket(int domain, int type, int protocol)
switch (type) { switch (type) {
case SOCK_RAW: case SOCK_RAW:
conn = netconn_new_with_proto_and_callback(NETCONN_RAW, protocol, event_callback); conn = netconn_new_with_proto_and_callback(NETCONN_RAW, protocol, event_callback);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_RAW, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_RAW, %d) = ",
domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
break; break;
case SOCK_DGRAM: case SOCK_DGRAM:
conn = netconn_new_with_callback(NETCONN_UDP, event_callback); conn = netconn_new_with_callback(NETCONN_UDP, event_callback);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_DGRAM, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_DGRAM, %d) = ",
domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
break; break;
case SOCK_STREAM: case SOCK_STREAM:
conn = netconn_new_with_callback(NETCONN_TCP, event_callback); conn = netconn_new_with_callback(NETCONN_TCP, event_callback);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_STREAM, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_STREAM, %d) = ",
domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
break; break;
default: default:
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%d, %d/UNKNOWN, %d) = -1\n", domain, type, protocol)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%d, %d/UNKNOWN, %d) = -1\n",
domain, type, protocol));
set_errno(EINVAL); set_errno(EINVAL);
return -1; return -1;
} }
@ -610,25 +620,20 @@ lwip_selscan(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset)
/* Go through each socket in each list to count number of sockets which /* Go through each socket in each list to count number of sockets which
currently match */ currently match */
for(i = 0; i < maxfdp1; i++) for(i = 0; i < maxfdp1; i++) {
{ if (FD_ISSET(i, readset)) {
if (FD_ISSET(i, readset))
{
/* See if netconn of this socket is ready for read */ /* See if netconn of this socket is ready for read */
p_sock = get_socket(i); p_sock = get_socket(i);
if (p_sock && (p_sock->lastdata || p_sock->rcvevent)) if (p_sock && (p_sock->lastdata || p_sock->rcvevent)) {
{
FD_SET(i, &lreadset); FD_SET(i, &lreadset);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for reading\n", i)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for reading\n", i));
nready++; nready++;
} }
} }
if (FD_ISSET(i, writeset)) if (FD_ISSET(i, writeset)) {
{
/* See if netconn of this socket is ready for write */ /* See if netconn of this socket is ready for write */
p_sock = get_socket(i); p_sock = get_socket(i);
if (p_sock && p_sock->sendevent) if (p_sock && p_sock->sendevent) {
{
FD_SET(i, &lwriteset); FD_SET(i, &lwriteset);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for writing\n", i)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for writing\n", i));
nready++; nready++;
@ -653,7 +658,9 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
struct lwip_select_cb select_cb; struct lwip_select_cb select_cb;
struct lwip_select_cb *p_selcb; struct lwip_select_cb *p_selcb;
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)); 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));
select_cb.next = 0; select_cb.next = 0;
select_cb.readset = readset; select_cb.readset = readset;
@ -682,10 +689,8 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
nready = lwip_selscan(maxfdp1, &lreadset, &lwriteset, &lexceptset); nready = lwip_selscan(maxfdp1, &lreadset, &lwriteset, &lexceptset);
/* If we don't have any current events, then suspend if we are supposed to */ /* If we don't have any current events, then suspend if we are supposed to */
if (!nready) if (!nready) {
{ if (timeout && timeout->tv_sec == 0 && timeout->tv_usec == 0) {
if (timeout && timeout->tv_sec == 0 && timeout->tv_usec == 0)
{
sys_sem_signal(selectsem); sys_sem_signal(selectsem);
if (readset) if (readset)
FD_ZERO(readset); FD_ZERO(readset);
@ -731,18 +736,18 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
if (select_cb_list == &select_cb) if (select_cb_list == &select_cb)
select_cb_list = select_cb.next; select_cb_list = select_cb.next;
else else
for (p_selcb = select_cb_list; p_selcb; p_selcb = p_selcb->next) for (p_selcb = select_cb_list; p_selcb; p_selcb = p_selcb->next) {
if (p_selcb->next == &select_cb) if (p_selcb->next == &select_cb) {
{
p_selcb->next = select_cb.next; p_selcb->next = select_cb.next;
break; break;
} }
}
sys_sem_signal(selectsem); sys_sem_signal(selectsem);
sys_sem_free(select_cb.sem); sys_sem_free(select_cb.sem);
if (i == 0) /* Timeout */ if (i == 0) {
{ /* Timeout */
if (readset) if (readset)
FD_ZERO(readset); FD_ZERO(readset);
if (writeset) if (writeset)
@ -771,8 +776,7 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
/* See what's set */ /* See what's set */
nready = lwip_selscan(maxfdp1, &lreadset, &lwriteset, &lexceptset); nready = lwip_selscan(maxfdp1, &lreadset, &lwriteset, &lexceptset);
} } else
else
sys_sem_signal(selectsem); sys_sem_signal(selectsem);
if (readset) if (readset)
@ -796,11 +800,9 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
struct lwip_select_cb *scb; struct lwip_select_cb *scb;
/* Get socket */ /* Get socket */
if (conn) if (conn) {
{
s = conn->socket; s = conn->socket;
if (s < 0) if (s < 0) {
{
/* Data comes in right away after an accept, even though /* Data comes in right away after an accept, even though
* the server task might not have created a new socket yet. * the server task might not have created a new socket yet.
* Just count down (or up) if that's the case and we * Just count down (or up) if that's the case and we
@ -814,14 +816,12 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
sock = get_socket(s); sock = get_socket(s);
if (!sock) if (!sock)
return; return;
} } else
else
return; return;
sys_sem_wait(selectsem); sys_sem_wait(selectsem);
/* Set event as required */ /* Set event as required */
switch (evt) switch (evt) {
{
case NETCONN_EVT_RCVPLUS: case NETCONN_EVT_RCVPLUS:
sock->rcvevent++; sock->rcvevent++;
break; break;
@ -844,13 +844,10 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
multiple times ONLY IF a select was actually waiting. We go through multiple times ONLY IF a select was actually waiting. We go through
the list the number of waiting select calls + 1. This list is the list the number of waiting select calls + 1. This list is
expected to be small. */ expected to be small. */
while (1) while (1) {
{
sys_sem_wait(selectsem); sys_sem_wait(selectsem);
for (scb = select_cb_list; scb; scb = scb->next) for (scb = select_cb_list; scb; scb = scb->next) {
{ if (scb->sem_signalled == 0) {
if (scb->sem_signalled == 0)
{
/* Test this select call for our socket */ /* Test this select call for our socket */
if (scb->readset && FD_ISSET(s, scb->readset)) if (scb->readset && FD_ISSET(s, scb->readset))
if (sock->rcvevent) if (sock->rcvevent)
@ -860,8 +857,7 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
break; break;
} }
} }
if (scb) if (scb) {
{
scb->sem_signalled = 1; scb->sem_signalled = 1;
sys_sem_signal(selectsem); sys_sem_signal(selectsem);
sys_sem_signal(scb->sem); sys_sem_signal(scb->sem);
@ -944,13 +940,13 @@ int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen)
int lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) int lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
{ {
int err = 0; int err = ERR_OK;
struct lwip_socket *sock = get_socket(s); struct lwip_socket *sock = get_socket(s);
if (!sock) if (!sock)
return -1; return -1;
if( NULL == optval || NULL == optlen ) { if ((NULL == optval) || (NULL == optlen)) {
sock_set_errno(sock, EFAULT); sock_set_errno(sock, EFAULT);
return -1; return -1;
} }
@ -990,9 +986,10 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
break; break;
default: default:
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n", s, optname)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n",
s, optname));
err = ENOPROTOOPT; err = ENOPROTOOPT;
} /* switch */ } /* switch (optname) */
break; break;
/* Level: IPPROTO_IP */ /* Level: IPPROTO_IP */
@ -1009,9 +1006,10 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
break; break;
default: default:
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, UNIMPL: optname=0x%x, ..)\n", s, optname)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, UNIMPL: optname=0x%x, ..)\n",
s, optname));
err = ENOPROTOOPT; err = ENOPROTOOPT;
} /* switch */ } /* switch (optname) */
break; break;
/* Level: IPPROTO_TCP */ /* Level: IPPROTO_TCP */
@ -1022,7 +1020,8 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
} }
/* If this is no TCP socket, ignore any options. */ /* If this is no TCP socket, ignore any options. */
if ( sock->conn->type != NETCONN_TCP ) return 0; if (sock->conn->type != NETCONN_TCP)
return 0;
switch (optname) { switch (optname) {
case TCP_NODELAY: case TCP_NODELAY:
@ -1035,19 +1034,21 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
break; break;
default: default:
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n", s, optname)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n",
s, optname));
err = ENOPROTOOPT; err = ENOPROTOOPT;
} /* switch */ } /* switch (optname */
break; break;
/* UNDEFINED LEVEL */ /* UNDEFINED LEVEL */
default: default:
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n", s, level, optname)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n",
s, level, optname));
err = ENOPROTOOPT; err = ENOPROTOOPT;
} /* switch */ } /* switch */
if( 0 != err ) { if (err != ERR_OK) {
sock_set_errno(sock, err); sock_set_errno(sock, err);
return -1; return -1;
} }
@ -1073,7 +1074,8 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
#endif /* SO_REUSE */ #endif /* SO_REUSE */
/*case SO_USELOOPBACK: UNIMPL */ /*case SO_USELOOPBACK: UNIMPL */
*(int*)optval = sock->conn->pcb.tcp->so_options & optname; *(int*)optval = sock->conn->pcb.tcp->so_options & optname;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, optname=0x%x, ..) = %s\n", s, optname, (*(int*)optval?"on":"off"))); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, optname=0x%x, ..) = %s\n",
s, optname, (*(int*)optval?"on":"off")));
break; break;
case SO_TYPE: case SO_TYPE:
@ -1091,15 +1093,19 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
break; break;
default: /* unrecognized socket type */ default: /* unrecognized socket type */
*(int*)optval = sock->conn->type; *(int*)optval = sock->conn->type;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_TYPE): unrecognized socket type %d\n", s, *(int *)optval)); LWIP_DEBUGF(SOCKETS_DEBUG,
} /* switch */ ("lwip_getsockopt(%d, SOL_SOCKET, SO_TYPE): unrecognized socket type %d\n",
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_TYPE) = %d\n", s, *(int *)optval)); s, *(int *)optval));
} /* switch (sock->conn->type) */
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_TYPE) = %d\n",
s, *(int *)optval));
break; break;
case SO_ERROR: case SO_ERROR:
*(int *)optval = sock->err; *(int *)optval = sock->err;
sock->err = 0; sock->err = 0;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_ERROR) = %d\n", s, *(int *)optval)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_ERROR) = %d\n",
s, *(int *)optval));
break; break;
#if LWIP_SO_RCVTIMEO #if LWIP_SO_RCVTIMEO
@ -1107,7 +1113,7 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
*(int *)optval = sock->conn->recv_timeout; *(int *)optval = sock->conn->recv_timeout;
break; break;
#endif /* LWIP_SO_RCVTIMEO */ #endif /* LWIP_SO_RCVTIMEO */
} /* switch */ } /* switch (optname) */
break; break;
/* Level: IPPROTO_IP */ /* Level: IPPROTO_IP */
@ -1115,13 +1121,15 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
switch (optname) { switch (optname) {
case IP_TTL: case IP_TTL:
*(int*)optval = sock->conn->pcb.tcp->ttl; *(int*)optval = sock->conn->pcb.tcp->ttl;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_TTL) = %d\n", s, *(int *)optval)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_TTL) = %d\n",
s, *(int *)optval));
break; break;
case IP_TOS: case IP_TOS:
*(int*)optval = sock->conn->pcb.tcp->tos; *(int*)optval = sock->conn->pcb.tcp->tos;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_TOS) = %d\n", s, *(int *)optval)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_TOS) = %d\n",
s, *(int *)optval));
break; break;
} /* switch */ } /* switch (optname) */
break; break;
/* Level: IPPROTO_TCP */ /* Level: IPPROTO_TCP */
@ -1129,31 +1137,36 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
switch (optname) { switch (optname) {
case TCP_NODELAY: case TCP_NODELAY:
*(int*)optval = (sock->conn->pcb.tcp->flags & TF_NODELAY); *(int*)optval = (sock->conn->pcb.tcp->flags & TF_NODELAY);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, TCP_NODELAY) = %s\n", s, (*(int*)optval)?"on":"off") ); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, TCP_NODELAY) = %s\n",
s, (*(int*)optval)?"on":"off") );
break; break;
case TCP_KEEPALIVE: case TCP_KEEPALIVE:
*(int*)optval = (int)sock->conn->pcb.tcp->keep_idle; *(int*)optval = (int)sock->conn->pcb.tcp->keep_idle;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPALIVE) = %d\n", s, *(int *)optval)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPALIVE) = %d\n",
s, *(int *)optval));
break; break;
#if LWIP_TCP_KEEPALIVE #if LWIP_TCP_KEEPALIVE
case TCP_KEEPIDLE: case TCP_KEEPIDLE:
*(int*)optval = (int)(sock->conn->pcb.tcp->keep_idle/1000); *(int*)optval = (int)(sock->conn->pcb.tcp->keep_idle/1000);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPIDLE) = %d\n", s, *(int *)optval)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPIDLE) = %d\n",
s, *(int *)optval));
break; break;
case TCP_KEEPINTVL: case TCP_KEEPINTVL:
*(int*)optval = (int)(sock->conn->pcb.tcp->keep_intvl/1000); *(int*)optval = (int)(sock->conn->pcb.tcp->keep_intvl/1000);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPINTVL) = %d\n", s, *(int *)optval)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPINTVL) = %d\n",
s, *(int *)optval));
break; break;
case TCP_KEEPCNT: case TCP_KEEPCNT:
*(int*)optval = (int)sock->conn->pcb.tcp->keep_cnt; *(int*)optval = (int)sock->conn->pcb.tcp->keep_cnt;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPCNT) = %d\n", s, *(int *)optval)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPCNT) = %d\n",
s, *(int *)optval));
break; break;
#endif /* LWIP_TCP_KEEPALIVE */ #endif /* LWIP_TCP_KEEPALIVE */
} /* switch */ } /* switch (optname) */
break; break;
} } /* switch (level) */
sock_set_errno(sock, err); sock_set_errno(sock, err);
return err ? -1 : 0; return err ? -1 : 0;
@ -1162,7 +1175,7 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
int lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) int lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
{ {
struct lwip_socket *sock = get_socket(s); struct lwip_socket *sock = get_socket(s);
int err = 0; int err = ERR_OK;
if (!sock) if (!sock)
return -1; return -1;
@ -1203,9 +1216,10 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
} }
break; break;
default: default:
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n", s, optname)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n",
s, optname));
err = ENOPROTOOPT; err = ENOPROTOOPT;
} /* switch */ } /* switch (optname) */
break; break;
/* Level: IPPROTO_IP */ /* Level: IPPROTO_IP */
@ -1222,24 +1236,22 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
break; break;
#if LWIP_IGMP #if LWIP_IGMP
case IP_MULTICAST_TTL: case IP_MULTICAST_TTL:
{
/* NOTE, some BSD implementation use "int", some others "char" */ /* NOTE, some BSD implementation use "int", some others "char" */
if ((optlen != sizeof(char)) && (optlen != sizeof(int))) if ((optlen != sizeof(char)) && (optlen != sizeof(int)))
err = EINVAL; err = EINVAL;
break; break;
}
case IP_ADD_MEMBERSHIP: case IP_ADD_MEMBERSHIP:
case IP_DROP_MEMBERSHIP: case IP_DROP_MEMBERSHIP:
{ if( optlen < sizeof(struct ip_mreq) ) { if (optlen < sizeof(struct ip_mreq)) {
err = EINVAL; err = EINVAL;
} }
break; break;
}
#endif /* LWIP_IGMP */ #endif /* LWIP_IGMP */
default: default:
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, UNIMPL: optname=0x%x, ..)\n", s, optname)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, UNIMPL: optname=0x%x, ..)\n",
s, optname));
err = ENOPROTOOPT; err = ENOPROTOOPT;
} /* switch */ } /* switch (optname) */
break; break;
/* Level: IPPROTO_TCP */ /* Level: IPPROTO_TCP */
@ -1250,7 +1262,8 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
} }
/* If this is no TCP socket, ignore any options. */ /* If this is no TCP socket, ignore any options. */
if ( sock->conn->type != NETCONN_TCP ) return 0; if (sock->conn->type != NETCONN_TCP)
return 0;
switch (optname) { switch (optname) {
case TCP_NODELAY: case TCP_NODELAY:
@ -1263,19 +1276,21 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
break; break;
default: default:
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n", s, optname)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n",
s, optname));
err = ENOPROTOOPT; err = ENOPROTOOPT;
} /* switch */ } /* switch (optname) */
break; break;
/* UNDEFINED LEVEL */ /* UNDEFINED LEVEL */
default: default:
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n", s, level, optname)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n",
s, level, optname));
err = ENOPROTOOPT; err = ENOPROTOOPT;
} /* switch */ } /* switch (level) */
if( 0 != err ) { if (err != ERR_OK) {
sock_set_errno(sock, err); sock_set_errno(sock, err);
return -1; return -1;
} }
@ -1305,14 +1320,15 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
} else { } else {
sock->conn->pcb.tcp->so_options &= ~optname; sock->conn->pcb.tcp->so_options &= ~optname;
} }
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, optname=0x%x, ..) -> %s\n", s, optname, (*(int*)optval?"on":"off"))); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, optname=0x%x, ..) -> %s\n",
s, optname, (*(int*)optval?"on":"off")));
break; break;
#if LWIP_SO_RCVTIMEO #if LWIP_SO_RCVTIMEO
case SO_RCVTIMEO: case SO_RCVTIMEO:
sock->conn->recv_timeout = ( *(int*)optval ); sock->conn->recv_timeout = ( *(int*)optval );
break; break;
#endif /* LWIP_SO_RCVTIMEO */ #endif /* LWIP_SO_RCVTIMEO */
} /* switch */ } /* switch (optname) */
break; break;
/* Level: IPPROTO_IP */ /* Level: IPPROTO_IP */
@ -1320,34 +1336,37 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
switch (optname) { switch (optname) {
case IP_TTL: case IP_TTL:
sock->conn->pcb.tcp->ttl = (u8_t)(*(int*)optval); sock->conn->pcb.tcp->ttl = (u8_t)(*(int*)optval);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TTL, ..) -> %u\n", s, sock->conn->pcb.tcp->ttl)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TTL, ..) -> %u\n",
s, sock->conn->pcb.tcp->ttl));
break; break;
case IP_TOS: case IP_TOS:
sock->conn->pcb.tcp->tos = (u8_t)(*(int*)optval); sock->conn->pcb.tcp->tos = (u8_t)(*(int*)optval);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TOS, ..)-> %u\n", s, sock->conn->pcb.tcp->tos)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TOS, ..)-> %u\n",
s, sock->conn->pcb.tcp->tos));
break; break;
#if LWIP_IGMP #if LWIP_IGMP
case IP_MULTICAST_TTL: case IP_MULTICAST_TTL:
{ if (optlen==sizeof(int)) sock->conn->pcb.tcp->ttl = (u8_t)(*(int*) optval); if (optlen == sizeof(int))
if (optlen==sizeof(u8_t)) sock->conn->pcb.tcp->ttl = (u8_t)(*(u8_t*)optval); sock->conn->pcb.tcp->ttl = (u8_t)(*(int*) optval);
if (optlen == sizeof(u8_t))
sock->conn->pcb.tcp->ttl = (u8_t)(*(u8_t*)optval);
break; break;
}
case IP_ADD_MEMBERSHIP: case IP_ADD_MEMBERSHIP:
case IP_DROP_MEMBERSHIP: case IP_DROP_MEMBERSHIP:
{ /* If this is a TCP or a RAW socket, ignore these options. */ /* If this is a TCP or a RAW socket, ignore these options. */
if ((sock->conn->type == NETCONN_TCP) || (sock->conn->type == NETCONN_RAW)) if ((sock->conn->type == NETCONN_TCP) || (sock->conn->type == NETCONN_RAW)) {
{ err = EAFNOSUPPORT; err = EAFNOSUPPORT;
} } else {
else struct ip_mreq *imr = (struct ip_mreq *)optval;
{ struct ip_mreq *imr = (struct ip_mreq *)optval; if (netconn_join_leave_group(sock->conn, (struct ip_addr *)&(imr->imr_multiaddr.s_addr),
if (netconn_join_leave_group( sock->conn, (struct ip_addr *)&(imr->imr_multiaddr.s_addr), (struct ip_addr *)&(imr->imr_interface.s_addr), ((optname==IP_ADD_MEMBERSHIP)?NETCONN_JOIN:NETCONN_LEAVE)) < 0) (struct ip_addr *)&(imr->imr_interface.s_addr),
{ err = EADDRNOTAVAIL; ((optname==IP_ADD_MEMBERSHIP)?NETCONN_JOIN:NETCONN_LEAVE)) < 0) {
err = EADDRNOTAVAIL;
} }
} }
break; break;
}
#endif /* LWIP_IGMP */ #endif /* LWIP_IGMP */
} /* switch */ } /* switch (optname) */
break; break;
/* Level: IPPROTO_TCP */ /* Level: IPPROTO_TCP */
@ -1359,31 +1378,36 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
} else { } else {
sock->conn->pcb.tcp->flags &= ~TF_NODELAY; sock->conn->pcb.tcp->flags &= ~TF_NODELAY;
} }
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_NODELAY) -> %s\n", s, (*(int *)optval)?"on":"off") ); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_NODELAY) -> %s\n",
s, (*(int *)optval)?"on":"off") );
break; break;
case TCP_KEEPALIVE: case TCP_KEEPALIVE:
sock->conn->pcb.tcp->keep_idle = (u32_t)(*(int*)optval); sock->conn->pcb.tcp->keep_idle = (u32_t)(*(int*)optval);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPALIVE) -> %lu\n", s, sock->conn->pcb.tcp->keep_idle)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPALIVE) -> %lu\n",
s, sock->conn->pcb.tcp->keep_idle));
break; break;
#if LWIP_TCP_KEEPALIVE #if LWIP_TCP_KEEPALIVE
case TCP_KEEPIDLE: case TCP_KEEPIDLE:
sock->conn->pcb.tcp->keep_idle = 1000*(u32_t)(*(int*)optval); sock->conn->pcb.tcp->keep_idle = 1000*(u32_t)(*(int*)optval);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPIDLE) -> %lu\n", s, sock->conn->pcb.tcp->keep_idle)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPIDLE) -> %lu\n",
s, sock->conn->pcb.tcp->keep_idle));
break; break;
case TCP_KEEPINTVL: case TCP_KEEPINTVL:
sock->conn->pcb.tcp->keep_intvl = 1000*(u32_t)(*(int*)optval); sock->conn->pcb.tcp->keep_intvl = 1000*(u32_t)(*(int*)optval);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPINTVL) -> %lu\n", s, sock->conn->pcb.tcp->keep_intvl)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPINTVL) -> %lu\n",
s, sock->conn->pcb.tcp->keep_intvl));
break; break;
case TCP_KEEPCNT: case TCP_KEEPCNT:
sock->conn->pcb.tcp->keep_cnt = (u32_t)(*(int*)optval); sock->conn->pcb.tcp->keep_cnt = (u32_t)(*(int*)optval);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPCNT) -> %lu\n", s, sock->conn->pcb.tcp->keep_cnt)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPCNT) -> %lu\n",
s, sock->conn->pcb.tcp->keep_cnt));
break; break;
#endif /* LWIP_TCP_KEEPALIVE */ #endif /* LWIP_TCP_KEEPALIVE */
} /* switch */ } /* switch (optname) */
break; break;
} /* switch */ } /* switch (level) */
sock_set_errno(sock, err); sock_set_errno(sock, err);
return err ? -1 : 0; return err ? -1 : 0;
@ -1431,7 +1455,7 @@ int lwip_ioctl(int s, long cmd, void *argp)
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, UNIMPL: 0x%lx, %p)\n", s, cmd, argp)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, UNIMPL: 0x%lx, %p)\n", s, cmd, argp));
sock_set_errno(sock, ENOSYS); /* not yet implemented */ sock_set_errno(sock, ENOSYS); /* not yet implemented */
return -1; return -1;
} } /* switch (cmd) */
} }
#endif /* !NO_SYS */ #endif /* !NO_SYS */