Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

sockets.h File Reference

#include "lwip/opt.h"

Include dependency graph for sockets.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  fd_set
struct  linger
struct  sockaddr
struct  sockaddr_in
struct  timeval

Defines

#define socklen_t   int
#define SOCK_STREAM   1
#define SOCK_DGRAM   2
#define SOCK_RAW   3
#define SO_DEBUG   0x0001
#define SO_ACCEPTCONN   0x0002
#define SO_REUSEADDR   0x0004
#define SO_KEEPALIVE   0x0008
#define SO_DONTROUTE   0x0010
#define SO_BROADCAST   0x0020
#define SO_USELOOPBACK   0x0040
#define SO_LINGER   0x0080
#define SO_OOBINLINE   0x0100
#define SO_DONTLINGER   (int)(~SO_LINGER)
#define SO_SNDBUF   0x1001
#define SO_RCVBUF   0x1002
#define SO_SNDLOWAT   0x1003
#define SO_RCVLOWAT   0x1004
#define SO_SNDTIMEO   0x1005
#define SO_RCVTIMEO   0x1006
#define SO_ERROR   0x1007
#define SO_TYPE   0x1008
#define SOL_SOCKET   0xfff
#define AF_UNSPEC   0
#define AF_INET   2
#define PF_INET   AF_INET
#define IPPROTO_TCP   6
#define IPPROTO_UDP   17
#define INADDR_ANY   0
#define INADDR_BROADCAST   0xffffffff
#define MSG_DONTWAIT   0x40
#define IOCPARM_MASK   0x7f
#define IOC_VOID   0x20000000
#define IOC_OUT   0x40000000
#define IOC_IN   0x80000000
#define IOC_INOUT   (IOC_IN|IOC_OUT)
#define _IO(x, y)   (IOC_VOID|((x)<<8)|(y))
#define _IOR(x, y, t)   (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
#define _IOW(x, y, t)   (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
#define FIONREAD   _IOR('f', 127, unsigned long)
#define FIONBIO   _IOW('f', 126, unsigned long)
#define SIOCSHIWAT   _IOW('s', 0, unsigned long)
#define SIOCGHIWAT   _IOR('s', 1, unsigned long)
#define SIOCSLOWAT   _IOW('s', 2, unsigned long)
#define SIOCGLOWAT   _IOR('s', 3, unsigned long)
#define SIOCATMARK   _IOR('s', 7, unsigned long)
#define O_NONBLOCK   04000
#define FD_SETSIZE   16
#define FD_SET(n, p)   ((p)->fd_bits[(n)/8] |= (1 << ((n) & 7)))
#define FD_CLR(n, p)   ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7)))
#define FD_ISSET(n, p)   ((p)->fd_bits[(n)/8] & (1 << ((n) & 7)))
#define FD_ZERO(p)   memset((void*)(p),0,sizeof(*(p)))

Typedefs

typedef fd_set fd_set

Functions

int lwip_accept (int s, struct sockaddr *addr, socklen_t *addrlen)
int lwip_bind (int s, struct sockaddr *name, socklen_t namelen)
int lwip_shutdown (int s, int how)
int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen)
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_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen)
int lwip_close (int s)
int lwip_connect (int s, struct sockaddr *name, socklen_t namelen)
int lwip_listen (int s, int backlog)
int lwip_recv (int s, void *mem, int len, unsigned int flags)
int lwip_read (int s, void *mem, int len)
int lwip_recvfrom (int s, void *mem, int len, unsigned int flags, struct sockaddr *from, socklen_t *fromlen)
int lwip_send (int s, void *dataptr, int size, unsigned int flags)
int lwip_sendto (int s, void *dataptr, int size, unsigned int flags, struct sockaddr *to, socklen_t tolen)
int lwip_socket (int domain, int type, int protocol)
int lwip_write (int s, void *dataptr, int size)
int lwip_select (int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout)
int lwip_ioctl (int s, long cmd, void *argp)


Define Documentation

#define _IO x,
 )     (IOC_VOID|((x)<<8)|(y))
 

Definition at line 137 of file sockets.h.

#define _IOR x,
y,
 )     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
 

Definition at line 139 of file sockets.h.

#define _IOW x,
y,
 )     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
 

Definition at line 141 of file sockets.h.

#define AF_INET   2
 

Definition at line 106 of file sockets.h.

Referenced by addr_callback(), ares_gethostbyaddr(), ares_gethostbyname(), ares_parse_a_reply(), dns_client(), fake_hostent(), gethostbyaddr(), gethostbynameaddr(), lwip_accept(), lwip_getpeername(), lwip_getsockname(), lwip_recvfrom(), main(), open_tcp_socket(), open_udp_socket(), and sock_udpclient().

#define AF_UNSPEC   0
 

Definition at line 105 of file sockets.h.

Referenced by lwip_connect().

#define FD_CLR n,
 )     ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7)))
 

Definition at line 168 of file sockets.h.

#define FD_ISSET n,
 )     ((p)->fd_bits[(n)/8] & (1 << ((n) & 7)))
 

Definition at line 169 of file sockets.h.

Referenced by event_callback(), lwip_selscan(), read_tcp_data(), read_udp_packets(), and write_tcp_data().

#define FD_SET n,
 )     ((p)->fd_bits[(n)/8] |= (1 << ((n) & 7)))
 

Definition at line 167 of file sockets.h.

Referenced by ares_fds(), and lwip_selscan().

#define FD_SETSIZE   16
 

Definition at line 166 of file sockets.h.

#define FD_ZERO  )     memset((void*)(p),0,sizeof(*(p)))
 

Definition at line 170 of file sockets.h.

Referenced by dns_client(), gethostbynameaddr(), lwip_select(), and lwip_selscan().

#define FIONBIO   _IOW('f', 126, unsigned long)
 

Definition at line 148 of file sockets.h.

Referenced by lwip_ioctl(), and open_tcp_socket().

#define FIONREAD   _IOR('f', 127, unsigned long)
 

Definition at line 145 of file sockets.h.

Referenced by lwip_ioctl().

#define INADDR_ANY   0
 

Definition at line 112 of file sockets.h.

Referenced by main(), and sock_udpclient().

#define INADDR_BROADCAST   0xffffffff
 

Definition at line 113 of file sockets.h.

#define IOC_IN   0x80000000
 

Definition at line 133 of file sockets.h.

#define IOC_INOUT   (IOC_IN|IOC_OUT)
 

Definition at line 134 of file sockets.h.

#define IOC_OUT   0x40000000
 

Definition at line 132 of file sockets.h.

#define IOC_VOID   0x20000000
 

Definition at line 131 of file sockets.h.

#define IOCPARM_MASK   0x7f
 

Definition at line 130 of file sockets.h.

#define IPPROTO_TCP   6
 

Definition at line 109 of file sockets.h.

#define IPPROTO_UDP   17
 

Definition at line 110 of file sockets.h.

#define MSG_DONTWAIT   0x40
 

Definition at line 116 of file sockets.h.

Referenced by lwip_recvfrom().

#define O_NONBLOCK   04000
 

Definition at line 161 of file sockets.h.

Referenced by lwip_ioctl(), lwip_recvfrom(), and open_tcp_socket().

#define PF_INET   AF_INET
 

Definition at line 107 of file sockets.h.

Referenced by lwip_socket().

#define SIOCATMARK   _IOR('s', 7, unsigned long)
 

Definition at line 157 of file sockets.h.

#define SIOCGHIWAT   _IOR('s', 1, unsigned long)
 

Definition at line 154 of file sockets.h.

#define SIOCGLOWAT   _IOR('s', 3, unsigned long)
 

Definition at line 156 of file sockets.h.

#define SIOCSHIWAT   _IOW('s', 0, unsigned long)
 

Definition at line 153 of file sockets.h.

#define SIOCSLOWAT   _IOW('s', 2, unsigned long)
 

Definition at line 155 of file sockets.h.

#define SO_ACCEPTCONN   0x0002
 

Definition at line 66 of file sockets.h.

#define SO_BROADCAST   0x0020
 

Definition at line 70 of file sockets.h.

#define SO_DEBUG   0x0001
 

Definition at line 65 of file sockets.h.

#define SO_DONTLINGER   (int)(~SO_LINGER)
 

Definition at line 75 of file sockets.h.

#define SO_DONTROUTE   0x0010
 

Definition at line 69 of file sockets.h.

#define SO_ERROR   0x1007
 

Definition at line 86 of file sockets.h.

Referenced by lwip_getsockopt().

#define SO_KEEPALIVE   0x0008
 

Definition at line 68 of file sockets.h.

#define SO_LINGER   0x0080
 

Definition at line 72 of file sockets.h.

#define SO_OOBINLINE   0x0100
 

Definition at line 73 of file sockets.h.

#define SO_RCVBUF   0x1002
 

Definition at line 81 of file sockets.h.

#define SO_RCVLOWAT   0x1004
 

Definition at line 83 of file sockets.h.

#define SO_RCVTIMEO   0x1006
 

Definition at line 85 of file sockets.h.

#define SO_REUSEADDR   0x0004
 

Definition at line 67 of file sockets.h.

Referenced by lwip_setsockopt().

#define SO_SNDBUF   0x1001
 

Definition at line 80 of file sockets.h.

#define SO_SNDLOWAT   0x1003
 

Definition at line 82 of file sockets.h.

#define SO_SNDTIMEO   0x1005
 

Definition at line 84 of file sockets.h.

#define SO_TYPE   0x1008
 

Definition at line 87 of file sockets.h.

#define SO_USELOOPBACK   0x0040
 

Definition at line 71 of file sockets.h.

#define SOCK_DGRAM   2
 

Definition at line 59 of file sockets.h.

Referenced by lwip_socket(), main(), and open_udp_socket().

#define SOCK_RAW   3
 

Definition at line 60 of file sockets.h.

#define SOCK_STREAM   1
 

Definition at line 58 of file sockets.h.

Referenced by lwip_socket(), main(), open_tcp_socket(), and sock_udpclient().

#define socklen_t   int
 

Definition at line 54 of file sockets.h.

#define SOL_SOCKET   0xfff
 

Definition at line 102 of file sockets.h.

Referenced by lwip_getsockopt(), and lwip_setsockopt().


Typedef Documentation

typedef struct fd_set fd_set
 


Function Documentation

int lwip_accept int  s,
struct sockaddr addr,
socklen_t *  addrlen
 

Definition at line 164 of file sockets.c.

References ip_addr::addr, AF_INET, alloc_socket(), netconn::callback, DEBUGF, event_callback(), get_socket(), htons, ip_addr_debug_print, netconn_accept(), netconn_delete(), netconn_peer(), newconn, in_addr::s_addr, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_len, sockaddr_in::sin_port, sock_set_errno, netconn::socket, SOCKETS_DEBUG, socksem, sys_sem_signal(), sys_sem_wait(), and u16_t.

00165 {
00166   struct lwip_socket *sock;
00167   struct netconn *newconn;
00168   struct ip_addr naddr;
00169   u16_t port;
00170   int newsock;
00171   struct sockaddr_in sin;
00172 
00173   DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d)...\n", s));
00174   sock = get_socket(s);
00175   if(!sock) {
00176     return -1;
00177   }
00178   
00179   newconn = netconn_accept(sock->conn);
00180     
00181   /* get the IP address and port of the remote host */
00182   netconn_peer(newconn, &naddr, &port);
00183   
00184   memset(&sin, 0, sizeof(sin));
00185   sin.sin_len = sizeof(sin);
00186   sin.sin_family = AF_INET;
00187   sin.sin_port = htons(port);
00188   sin.sin_addr.s_addr = naddr.addr;
00189 
00190   if(*addrlen > sizeof(sin))
00191       *addrlen = sizeof(sin);
00192 
00193   memcpy(addr, &sin, *addrlen);
00194 
00195   newsock = alloc_socket(newconn);
00196   if(newsock == -1) {  
00197     netconn_delete(newconn);
00198         sock_set_errno(sock, ENOBUFS);
00199         return -1;
00200   }
00201   newconn->callback = event_callback;
00202   sock = get_socket(newsock);
00203   
00204   sys_sem_wait(socksem);
00205   sock->rcvevent += -1 - newconn->socket;
00206   newconn->socket = newsock;
00207   sys_sem_signal(socksem);
00208 
00209 #if SOCKETS_DEBUG
00210   DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d) returning new sock=%d addr=", s, newsock));
00211   ip_addr_debug_print(&naddr);
00212   DEBUGF(SOCKETS_DEBUG, (" port=%u\n", port));
00213 #endif
00214   
00215   sock_set_errno(sock, 0);
00216   return newsock;
00217 }

Here is the call graph for this function:

int lwip_bind int  s,
struct sockaddr name,
socklen_t  namelen
 

Definition at line 220 of file sockets.c.

References ip_addr::addr, DEBUGF, ERR_OK, err_t, err_to_errno, get_socket(), ip_addr_debug_print, name, netconn_bind(), ntohs, sock_set_errno, SOCKETS_DEBUG, and u16_t.

00221 {
00222   struct lwip_socket *sock;
00223   struct ip_addr local_addr;
00224   u16_t local_port;
00225   err_t err;
00226   
00227   sock = get_socket(s);
00228   if(!sock) {
00229     return -1;
00230   }
00231   
00232   local_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr;
00233   local_port = ((struct sockaddr_in *)name)->sin_port;
00234 
00235 #if SOCKETS_DEBUG
00236   DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d, addr=", s));
00237   ip_addr_debug_print(&local_addr);
00238   DEBUGF(SOCKETS_DEBUG, (" port=%u)\n", ntohs(local_port)));
00239 #endif
00240   
00241   err = netconn_bind(sock->conn, &local_addr, ntohs(local_port));
00242 
00243   if(err != ERR_OK) {
00244         DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d) failed, err=%d\n", s, err));
00245         sock_set_errno(sock, err_to_errno(err));
00246     return -1;
00247   }
00248 
00249   DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d) succeeded\n", s));
00250   sock_set_errno(sock, 0);
00251   return 0;
00252 }

Here is the call graph for this function:

int lwip_close int  s  ) 
 

Definition at line 255 of file sockets.c.

References DEBUGF, get_socket(), netbuf_delete(), netconn_delete(), NULL, sock_set_errno, SOCKETS_DEBUG, socksem, sys_sem_new(), sys_sem_signal(), and sys_sem_wait().

Referenced by lwip_shutdown().

00256 {
00257   struct lwip_socket *sock;
00258   
00259   DEBUGF(SOCKETS_DEBUG, ("lwip_close(%d)\n", s));
00260   if (!socksem)
00261       socksem = sys_sem_new(1);
00262 
00263   /* We cannot allow multiple closes of the same socket. */
00264   sys_sem_wait(socksem);
00265   
00266   sock = get_socket(s);
00267   if(!sock) {
00268       sys_sem_signal(socksem);
00269       return -1;
00270   }
00271   
00272   netconn_delete(sock->conn);
00273   if(sock->lastdata) {
00274     netbuf_delete(sock->lastdata);
00275   }
00276   sock->lastdata = NULL;
00277   sock->lastoffset = 0;
00278   sock->conn = NULL;
00279   sys_sem_signal(socksem);
00280   sock_set_errno(sock, 0);
00281   return 0;
00282 }

Here is the call graph for this function:

int lwip_connect int  s,
struct sockaddr name,
socklen_t  namelen
 

Definition at line 285 of file sockets.c.

References ip_addr::addr, AF_UNSPEC, DEBUGF, ERR_OK, err_t, err_to_errno, get_socket(), ip_addr_debug_print, name, netconn_connect(), netconn_disconnect(), ntohs, sock_set_errno, SOCKETS_DEBUG, and u16_t.

00286 {
00287   struct lwip_socket *sock;
00288   err_t err;
00289 
00290   sock = get_socket(s);
00291   if(!sock) {
00292     return -1;
00293   }
00294   
00295   if (((struct sockaddr_in *)name)->sin_family == AF_UNSPEC) {
00296         DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, AF_UNSPEC)\n", s));
00297         err = netconn_disconnect(sock->conn);
00298   } else {
00299         struct ip_addr remote_addr;
00300         u16_t remote_port;
00301 
00302         remote_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr;
00303         remote_port = ((struct sockaddr_in *)name)->sin_port;
00304 
00305 #if SOCKETS_DEBUG
00306         DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, addr=", s));
00307         ip_addr_debug_print(&remote_addr);
00308         DEBUGF(SOCKETS_DEBUG, (" port=%u)\n", ntohs(remote_port)));
00309 #endif
00310         
00311         err = netconn_connect(sock->conn, &remote_addr, ntohs(remote_port));
00312    }
00313 
00314   if(err != ERR_OK) {
00315         DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d) failed, err=%d\n", s, err));
00316         sock_set_errno(sock, err_to_errno(err));
00317     return -1;
00318   }
00319 
00320   DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d) succeeded\n", s));
00321   sock_set_errno(sock, 0);
00322   return 0;
00323 }

Here is the call graph for this function:

int lwip_getpeername int  s,
struct sockaddr name,
socklen_t *  namelen
 

Definition at line 893 of file sockets.c.

References ip_addr::addr, AF_INET, DEBUGF, get_socket(), htons, ip_addr_debug_print, lwip_socket(), name, netconn_peer(), in_addr::s_addr, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_len, sockaddr_in::sin_port, sock_set_errno, and SOCKETS_DEBUG.

00894 {
00895   struct lwip_socket *sock;
00896   struct sockaddr_in sin;
00897   struct ip_addr naddr;
00898 
00899   sock = get_socket(s);
00900   if(!sock) {
00901     return -1;
00902   }
00903   
00904   memset(&sin, 0, sizeof(sin));
00905   sin.sin_len = sizeof(sin);
00906   sin.sin_family = AF_INET;
00907 
00908   /* get the IP address and port of the remote host */
00909   netconn_peer(sock->conn, &naddr, &sin.sin_port);
00910   
00911 #if SOCKETS_DEBUG
00912   DEBUGF(SOCKETS_DEBUG, ("lwip_getpeername(%d, addr=", s));
00913   ip_addr_debug_print(&naddr);
00914   DEBUGF(SOCKETS_DEBUG, (" port=%d)\n", sin.sin_port));
00915 #endif
00916   
00917   sin.sin_port = htons(sin.sin_port);
00918   sin.sin_addr.s_addr = naddr.addr;
00919 
00920   if(*namelen > sizeof(sin))
00921       *namelen = sizeof(sin);
00922 
00923   memcpy(name, &sin, *namelen);
00924   sock_set_errno(sock, 0);
00925   return 0;
00926 }

Here is the call graph for this function:

int lwip_getsockname int  s,
struct sockaddr name,
socklen_t *  namelen
 

Definition at line 928 of file sockets.c.

References AF_INET, DEBUGF, get_socket(), htons, ip_addr_debug_print, lwip_socket(), name, netconn_addr(), in_addr::s_addr, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_len, sockaddr_in::sin_port, sock_set_errno, and SOCKETS_DEBUG.

00929 {
00930   struct lwip_socket *sock;
00931   struct sockaddr_in sin;
00932   struct ip_addr *naddr;
00933 
00934   sock = get_socket(s);
00935   if(!sock) {
00936     return -1;
00937   }
00938   
00939   memset(&sin, 0, sizeof(sin));
00940   sin.sin_len = sizeof(sin);
00941   sin.sin_family = AF_INET;
00942 
00943   /* get the IP address and port of the remote host */
00944   netconn_addr(sock->conn, &naddr, &sin.sin_port);
00945 
00946 #if SOCKETS_DEBUG
00947   DEBUGF(SOCKETS_DEBUG, ("lwip_getsockname(%d, addr=", s));
00948   ip_addr_debug_print(naddr);
00949   DEBUGF(SOCKETS_DEBUG, (" port=%d)\n", sin.sin_port));
00950 #endif
00951   
00952   sin.sin_port = htons(sin.sin_port);
00953   sin.sin_addr.s_addr = naddr->addr;
00954 
00955   if(*namelen > sizeof(sin))
00956       *namelen = sizeof(sin);
00957 
00958   memcpy(name, &sin, *namelen);
00959   sock_set_errno(sock, 0);
00960   return 0;
00961 }

Here is the call graph for this function:

int lwip_getsockopt int  s,
int  level,
int  optname,
void *  optval,
socklen_t *  optlen
 

Definition at line 963 of file sockets.c.

References DEBUGF, get_socket(), lwip_socket(), SO_ERROR, sock_set_errno, SOCKETS_DEBUG, and SOL_SOCKET.

00964 {
00965         int err = ENOSYS;
00966         struct lwip_socket *sock = get_socket(s);
00967 
00968         if(!sock) {
00969                 return -1;
00970         }
00971 
00972         if(level == SOL_SOCKET) {
00973                 switch(optname) {
00974                         case SO_ERROR:
00975                                 if(!optval || !optlen || (*optlen != sizeof(int))) {
00976                                         err = EINVAL;
00977                                         break;
00978                                 }
00979                                 *(int *)optval = sock->err;
00980                                 sock->err = 0;
00981                                 DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_ERROR) = %d\n", s, *(int *)optval));
00982                                 err = 0;
00983                                 break;
00984                         default:
00985                                 DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n", s, optname));
00986                                 break;
00987                 }
00988         } else {
00989                 DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n", s, level, optname));
00990         }
00991         sock_set_errno(sock, err);
00992         return err ? -1 : 0;
00993 }

Here is the call graph for this function:

int lwip_ioctl int  s,
long  cmd,
void *  argp
 

Definition at line 1023 of file sockets.c.

References DEBUGF, FIONBIO, FIONREAD, get_socket(), lwip_socket(), O_NONBLOCK, sock_set_errno, SOCKETS_DEBUG, u16_t, and u32_t.

Referenced by open_tcp_socket().

01024 {
01025         struct lwip_socket *sock = get_socket(s);
01026 
01027         if(!sock) {
01028                 return -1;
01029         }
01030 
01031         switch(cmd) {
01032         case FIONREAD:
01033                 if(!argp) {
01034                         sock_set_errno(sock, EINVAL);
01035                         return -1;
01036                 }
01037 
01038                 *((u16_t*)argp) = sock->conn->recv_avail;
01039 
01040                 DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, FIONREAD, %p) = %u\n", s, argp, *((u16_t*)argp)));
01041                 sock_set_errno(sock, 0);
01042                 return 0;
01043 
01044         case FIONBIO:
01045                 if(argp && *(u32_t*)argp)
01046                         sock->flags |= O_NONBLOCK;
01047                 else
01048                         sock->flags &= ~O_NONBLOCK;
01049                 DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, FIONBIO, %d)\n", s, !!(sock->flags & O_NONBLOCK)));
01050                 sock_set_errno(sock, 0);
01051                 return 0;
01052 
01053         default:
01054                 DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, UNIMPL: 0x%lx, %p)\n", s, cmd, argp));
01055                 sock_set_errno(sock, ENOSYS); /* not yet implemented */
01056                 return -1;
01057         }
01058 }

Here is the call graph for this function:

int lwip_listen int  s,
int  backlog
 

Definition at line 326 of file sockets.c.

References DEBUGF, ERR_OK, err_t, err_to_errno, get_socket(), netconn_listen(), sock_set_errno, and SOCKETS_DEBUG.

00327 {
00328   struct lwip_socket *sock;    
00329   err_t err;
00330   
00331   DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d, backlog=%d)\n", s, backlog));
00332   sock = get_socket(s);
00333   if(!sock) {
00334     return -1;
00335   }
00336  
00337   err = netconn_listen(sock->conn);
00338 
00339   if(err != ERR_OK) {
00340         DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d) failed, err=%d\n", s, err));
00341         sock_set_errno(sock, err_to_errno(err));
00342     return -1;
00343   }
00344 
00345   sock_set_errno(sock, 0);
00346   return 0;
00347 }

Here is the call graph for this function:

int lwip_read int  s,
void *  mem,
int  len
 

Definition at line 458 of file sockets.c.

References len, lwip_recvfrom(), and NULL.

00459 {
00460   return lwip_recvfrom(s, mem, len, 0, NULL, NULL);
00461 }

Here is the call graph for this function:

int lwip_recv int  s,
void *  mem,
int  len,
unsigned int  flags
 

Definition at line 464 of file sockets.c.

References len, lwip_recvfrom(), and NULL.

00465 {
00466   return lwip_recvfrom(s, mem, len, flags, NULL, NULL);
00467 }

Here is the call graph for this function:

int lwip_recvfrom int  s,
void *  mem,
int  len,
unsigned int  flags,
struct sockaddr from,
socklen_t *  fromlen
 

Definition at line 350 of file sockets.c.

References AF_INET, DEBUGF, get_socket(), htons, ip_addr_debug_print, len, MSG_DONTWAIT, netbuf_copy_partial(), netbuf_delete(), netbuf_fromaddr(), netbuf_fromport(), netbuf_len(), netconn_recv(), NETCONN_TCP, netconn_type, NULL, O_NONBLOCK, in_addr::s_addr, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_len, sockaddr_in::sin_port, sock_set_errno, SOCKETS_DEBUG, and u16_t.

Referenced by lwip_read(), and lwip_recv().

00352 {
00353   struct lwip_socket *sock;
00354   struct netbuf *buf;
00355   u16_t buflen, copylen;
00356   struct ip_addr *addr;
00357   u16_t port;
00358 
00359   
00360   DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d, %p, %d, 0x%x, ..)\n", s, mem, len, flags));
00361   sock = get_socket(s);
00362   if(!sock) {
00363     return -1;
00364   }
00365 
00366   /* Check if there is data left from the last recv operation. */
00367   if(sock->lastdata) {    
00368     buf = sock->lastdata;
00369   } else {
00370     /* If this is non-blocking call, then check first */
00371     if (((flags & MSG_DONTWAIT) || (sock->flags & O_NONBLOCK))
00372         && !sock->rcvevent)
00373     {
00374       DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): returning EWOULDBLOCK\n", s));
00375       sock_set_errno(sock, EWOULDBLOCK);
00376       return -1;
00377     }
00378       
00379     /* No data was left from the previous operation, so we try to get
00380        some from the network. */
00381     buf = netconn_recv(sock->conn);
00382     
00383     if(!buf) {
00384       /* We should really do some error checking here. */
00385       DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): buf == NULL!\n", s));
00386       sock_set_errno(sock, 0);
00387       return 0;
00388     }
00389   }
00390   
00391   buflen = netbuf_len(buf);
00392 
00393   buflen -= sock->lastoffset;
00394   
00395   if(len > buflen) {
00396     copylen = buflen;
00397   } else {
00398     copylen = len;
00399   }
00400   
00401   /* copy the contents of the received buffer into
00402      the supplied memory pointer mem */
00403   netbuf_copy_partial(buf, mem, copylen, sock->lastoffset);
00404 
00405   /* Check to see from where the data was. */
00406   if(from && fromlen) {
00407     struct sockaddr_in sin;
00408 
00409     addr = netbuf_fromaddr(buf);
00410     port = netbuf_fromport(buf);
00411 
00412     memset(&sin, 0, sizeof(sin));
00413     sin.sin_len = sizeof(sin);
00414     sin.sin_family = AF_INET;
00415     sin.sin_port = htons(port);
00416     sin.sin_addr.s_addr = addr->addr;
00417 
00418     if(*fromlen > sizeof(sin))
00419       *fromlen = sizeof(sin);
00420 
00421     memcpy(from, &sin, *fromlen);
00422 
00423 #if SOCKETS_DEBUG
00424     DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): addr=", s));
00425     ip_addr_debug_print(addr);
00426     DEBUGF(SOCKETS_DEBUG, (" port=%u len=%u\n", port, copylen));
00427 #endif
00428   } else {
00429 #if SOCKETS_DEBUG > 0
00430     addr = netbuf_fromaddr(buf);
00431     port = netbuf_fromport(buf);  
00432 
00433     DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): addr=", s));
00434     ip_addr_debug_print(addr);
00435     DEBUGF(SOCKETS_DEBUG, (" port=%u len=%u\n", port, copylen));
00436 #endif
00437 
00438   }
00439  
00440   /* If this is a TCP socket, check if there is data left in the
00441      buffer. If so, it should be saved in the sock structure for next
00442      time around. */
00443   if(netconn_type(sock->conn) == NETCONN_TCP && buflen - copylen > 0) {
00444     sock->lastdata = buf;
00445     sock->lastoffset += copylen;
00446   } else {
00447     sock->lastdata = NULL;
00448     sock->lastoffset = 0;
00449     netbuf_delete(buf);
00450   }
00451 
00452  
00453   sock_set_errno(sock, 0);
00454   return copylen;
00455 }

Here is the call graph for this function:

int lwip_select int  maxfdp1,
fd_set readset,
fd_set writeset,
fd_set exceptset,
struct timeval timeout
 

Definition at line 657 of file sockets.c.

References DEBUGF, lwip_select_cb::exceptset, FD_ZERO, lwip_selscan(), lwip_select_cb::next, lwip_select_cb::readset, select_cb_list, selectsem, lwip_select_cb::sem, lwip_select_cb::sem_signalled, set_errno, SOCKETS_DEBUG, sys_sem_free(), sys_sem_new(), sys_sem_signal(), sys_sem_wait(), sys_sem_wait_timeout(), timeval::tv_sec, timeval::tv_usec, u32_t, and lwip_select_cb::writeset.

00659 {
00660     int i;
00661     int nready;
00662     fd_set lreadset, lwriteset, lexceptset;
00663     u32_t msectimeout;
00664     struct lwip_select_cb select_cb;
00665     struct lwip_select_cb *p_selcb;
00666 
00667         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));
00668     select_cb.next = 0;
00669     select_cb.readset = readset;
00670     select_cb.writeset = writeset;
00671     select_cb.exceptset = exceptset;
00672     select_cb.sem_signalled = 0;
00673     
00674     /* Protect ourselves searching through the list */
00675     if (!selectsem)
00676         selectsem = sys_sem_new(1);
00677     sys_sem_wait(selectsem);
00678     
00679     if (readset)
00680         lreadset = *readset;
00681     else
00682         FD_ZERO(&lreadset);
00683     if (writeset)
00684         lwriteset = *writeset;
00685     else
00686         FD_ZERO(&lwriteset);
00687     if (exceptset)
00688         lexceptset = *exceptset;
00689     else
00690         FD_ZERO(&lexceptset);
00691     
00692     /* Go through each socket in each list to count number of sockets which
00693        currently match */
00694     nready = lwip_selscan(maxfdp1, &lreadset, &lwriteset, &lexceptset);
00695     
00696     /* If we don't have any current events, then suspend if we are supposed to */
00697     if (!nready)
00698     {
00699         if (timeout && timeout->tv_sec == 0 && timeout->tv_usec == 0)
00700         {
00701             sys_sem_signal(selectsem);
00702             if (readset)
00703                 FD_ZERO(readset);
00704             if (writeset)
00705                 FD_ZERO(writeset);
00706             if (exceptset)
00707                 FD_ZERO(exceptset);
00708 
00709                         DEBUGF(SOCKETS_DEBUG, ("lwip_select: no timeout, returning 0\n"));
00710                         set_errno(0);
00711             return 0;
00712         }
00713         
00714         /* add our semaphore to list */
00715         /* We don't actually need any dynamic memory. Our entry on the
00716          * list is only valid while we are in this function, so it's ok
00717          * to use local variables */
00718 
00719         select_cb.sem = sys_sem_new(0);
00720         /* Note that we are still protected */
00721         /* Put this select_cb on top of list */
00722         select_cb.next = select_cb_list;
00723         select_cb_list = &select_cb;
00724 
00725         /* Now we can safely unprotect */
00726         sys_sem_signal(selectsem);
00727 
00728         /* Now just wait to be woken */
00729         if (timeout == 0)
00730             /* Wait forever */
00731             msectimeout = 0;
00732         else
00733             msectimeout =  ((timeout->tv_sec * 1000) + (timeout->tv_usec /1000));
00734 
00735         i = sys_sem_wait_timeout(select_cb.sem, msectimeout);
00736 
00737         /* Take us off the list */
00738         sys_sem_wait(selectsem);
00739         if (select_cb_list == &select_cb)
00740             select_cb_list = select_cb.next;
00741         else
00742             for (p_selcb = select_cb_list; p_selcb; p_selcb = p_selcb->next)
00743                 if (p_selcb->next == &select_cb)
00744                 {
00745                     p_selcb->next = select_cb.next;
00746                     break;
00747                 }
00748         
00749         sys_sem_signal(selectsem);
00750         
00751         sys_sem_free(select_cb.sem);
00752         if (i == 0)             /* Timeout */
00753         {
00754             if (readset)
00755                 FD_ZERO(readset);
00756             if (writeset)
00757                 FD_ZERO(writeset);
00758             if (exceptset)
00759                 FD_ZERO(exceptset);
00760                         DEBUGF(SOCKETS_DEBUG, ("lwip_select: timeout expired\n"));
00761                         set_errno(0);
00762             return 0;
00763         }
00764 
00765         if (readset)
00766             lreadset = *readset;
00767         else
00768             FD_ZERO(&lreadset);
00769         if (writeset)
00770             lwriteset = *writeset;
00771         else
00772             FD_ZERO(&lwriteset);
00773         if (exceptset)
00774             lexceptset = *exceptset;
00775         else
00776             FD_ZERO(&lexceptset);
00777 
00778         /* See what's set */
00779         nready = lwip_selscan(maxfdp1, &lreadset, &lwriteset, &lexceptset);
00780     }
00781     else
00782         sys_sem_signal(selectsem);
00783     
00784     if (readset)
00785         *readset = lreadset;
00786     if (writeset)
00787         *writeset = lwriteset;
00788     if (exceptset)
00789         *exceptset = lexceptset;
00790         DEBUGF(SOCKETS_DEBUG, ("lwip_select: nready=%d\n", nready));
00791         set_errno(0);
00792     return nready;
00793 }

Here is the call graph for this function:

int lwip_send int  s,
void *  dataptr,
int  size,
unsigned int  flags
 

Definition at line 470 of file sockets.c.

References data, DEBUGF, ERR_ARG, ERR_OK, err_t, err_to_errno, get_socket(), netbuf_delete(), netbuf_new(), netbuf_ref(), NETCONN_COPY, netconn_send(), NETCONN_TCP, netconn_type, NETCONN_UDP, netconn_write(), sock_set_errno, and SOCKETS_DEBUG.

Referenced by lwip_sendto(), and lwip_write().

00471 {
00472   struct lwip_socket *sock;
00473   struct netbuf *buf;
00474   err_t err;
00475 
00476   DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d, data=%p, size=%d, flags=0x%x)\n", s, data, size, flags));
00477 
00478   sock = get_socket(s);
00479   if(!sock) {
00480     return -1;
00481   }  
00482   
00483   switch(netconn_type(sock->conn)) {
00484   case NETCONN_UDP:
00485     /* create a buffer */
00486     buf = netbuf_new();
00487 
00488     if(!buf) {
00489           DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) ENOBUFS\n", s));
00490           sock_set_errno(sock, ENOBUFS);
00491       return -1;
00492     }
00493     
00494     /* make the buffer point to the data that should
00495        be sent */
00496     netbuf_ref(buf, data, size);
00497 
00498     /* send the data */
00499     err = netconn_send(sock->conn, buf);
00500 
00501     /* deallocated the buffer */
00502     netbuf_delete(buf);
00503     break;
00504   case NETCONN_TCP:
00505     err = netconn_write(sock->conn, data, size, NETCONN_COPY);
00506     break;
00507   default:
00508     err = ERR_ARG;
00509     break;
00510   }
00511   if(err != ERR_OK) {
00512         DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) err=%d\n", s, err));
00513         sock_set_errno(sock, err_to_errno(err));
00514     return -1;    
00515   }
00516 
00517   DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) ok size=%d\n", s, size));
00518   sock_set_errno(sock, 0);
00519   return size;
00520 }

Here is the call graph for this function:

int lwip_sendto int  s,
void *  dataptr,
int  size,
unsigned int  flags,
struct sockaddr to,
socklen_t  tolen
 

Definition at line 523 of file sockets.c.

References ip_addr::addr, data, DEBUGF, ERR_OK, get_socket(), ip_addr_debug_print, lwip_send(), netconn_connect(), netconn_disconnect(), netconn_peer(), ntohs, SOCKETS_DEBUG, and u16_t.

00525 {
00526   struct lwip_socket *sock;
00527   struct ip_addr remote_addr, addr;
00528   u16_t remote_port, port;
00529   int ret,connected;
00530 
00531   sock = get_socket(s);
00532   if(!sock) {
00533     return -1;
00534   }
00535   
00536   /* get the peer if currently connected */
00537   connected = (netconn_peer(sock->conn, &addr, &port) == ERR_OK);
00538   
00539   remote_addr.addr = ((struct sockaddr_in *)to)->sin_addr.s_addr;
00540   remote_port = ((struct sockaddr_in *)to)->sin_port;
00541 
00542 #if SOCKETS_DEBUG
00543   DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, size=%d, flags=0x%x to=", s, data, size, flags));
00544   ip_addr_debug_print(&remote_addr);
00545   DEBUGF(SOCKETS_DEBUG, (" port=%u\n", ntohs(remote_port)));
00546 #endif
00547   
00548   netconn_connect(sock->conn, &remote_addr, ntohs(remote_port));
00549   
00550   ret = lwip_send(s, data, size, flags);
00551 
00552   /* reset the remote address and port number
00553      of the connection */
00554   if(connected)
00555         netconn_connect(sock->conn, &addr, port);
00556   else
00557         netconn_disconnect(sock->conn);
00558   return ret;
00559 }

Here is the call graph for this function:

int lwip_setsockopt int  s,
int  level,
int  optname,
const void *  optval,
socklen_t  optlen
 

Definition at line 995 of file sockets.c.

References DEBUGF, get_socket(), lwip_socket(), SO_REUSEADDR, sock_set_errno, SOCKETS_DEBUG, and SOL_SOCKET.

00996 {
00997         struct lwip_socket *sock = get_socket(s);
00998         int err = ENOSYS;
00999 
01000         if(!sock) {
01001                 return -1;
01002         }
01003 
01004         if(level == SOL_SOCKET) {
01005                 switch(optname) {
01006                         case SO_REUSEADDR:
01007                                 DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, SO_REUSEADDR, ..)\n", s));
01008                                 /* XXX just pretend we support this for now */
01009                                 err = 0;
01010                                 break;
01011                         default:
01012                                 DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n", s, optname));
01013                                 break;
01014                 }
01015         } else {
01016                 DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n", s, level, optname));
01017         }
01018 
01019         sock_set_errno(sock, err);
01020         return err ? -1 : 0;
01021 }

Here is the call graph for this function:

int lwip_shutdown int  s,
int  how
 

Definition at line 887 of file sockets.c.

References DEBUGF, lwip_close(), and SOCKETS_DEBUG.

00888 {
00889         DEBUGF(SOCKETS_DEBUG, ("lwip_shutdown(%d, how=%d)\n", s, how));
00890     return lwip_close(s); /* XXX temporary hack until proper implementation */
00891 }

Here is the call graph for this function:

int lwip_socket int  domain,
int  type,
int  protocol
 

Definition at line 562 of file sockets.c.

References alloc_socket(), conn, DEBUGF, event_callback(), netconn_delete(), netconn_new_with_callback(), NETCONN_TCP, NETCONN_UDP, PF_INET, set_errno, SOCK_DGRAM, SOCK_STREAM, netconn::socket, and SOCKETS_DEBUG.

Referenced by event_callback(), lwip_getpeername(), lwip_getsockname(), lwip_getsockopt(), lwip_ioctl(), lwip_selscan(), and lwip_setsockopt().

00563 {
00564   struct netconn *conn;
00565   int i;
00566 
00567   /* create a netconn */
00568   switch(type) {
00569   case SOCK_DGRAM:
00570     conn = netconn_new_with_callback(NETCONN_UDP, event_callback);
00571         DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_DGRAM, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
00572     break;
00573   case SOCK_STREAM:
00574     conn = netconn_new_with_callback(NETCONN_TCP, event_callback);
00575         DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_STREAM, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
00576     break;
00577   default:
00578         DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%d, %d/UNKNOWN, %d) = -1\n", domain, type, protocol));
00579         set_errno(EINVAL);
00580     return -1;
00581   }
00582 
00583   if(!conn) {
00584     DEBUGF(SOCKETS_DEBUG, ("-1 / ENOBUFS (could not create netconn)\n"));
00585         set_errno(ENOBUFS);
00586     return -1;
00587   }
00588 
00589   i = alloc_socket(conn);
00590 
00591   if(i == -1) {
00592     netconn_delete(conn);
00593         set_errno(ENOBUFS);
00594         return -1;
00595   }
00596   conn->socket = i;
00597   DEBUGF(SOCKETS_DEBUG, ("%d\n", i));
00598   set_errno(0);
00599   return i;
00600 }

Here is the call graph for this function:

int lwip_write int  s,
void *  dataptr,
int  size
 

Definition at line 603 of file sockets.c.

References data, and lwip_send().

00604 {
00605    return lwip_send(s, data, size, 0);
00606 }

Here is the call graph for this function:


Generated on Wed Jan 14 12:59:13 2004 for RTL-lwIP-0.4 by doxygen 1.3.4