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

sockets.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
00003  * All rights reserved. 
00004  * 
00005  * Redistribution and use in source and binary forms, with or without modification, 
00006  * are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  *    this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright notice,
00011  *    this list of conditions and the following disclaimer in the documentation
00012  *    and/or other materials provided with the distribution.
00013  * 3. The name of the author may not be used to endorse or promote products
00014  *    derived from this software without specific prior written permission. 
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
00017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
00019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
00021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
00024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
00025  * OF SUCH DAMAGE.
00026  *
00027  * This file is part of the lwIP TCP/IP stack.
00028  * 
00029  * Author: Adam Dunkels <adam@sics.se>
00030  *
00031  */
00032 
00033 
00034 #ifndef __LWIP_SOCKETS_H__
00035 #define __LWIP_SOCKETS_H__
00036 
00037 #include "lwip/opt.h"
00038 
00039 struct sockaddr_in {
00040   u8_t sin_len;
00041   u8_t sin_family;
00042   u16_t sin_port;
00043   struct in_addr sin_addr;
00044   char sin_zero[8];
00045 };
00046 
00047 struct sockaddr {
00048   u8_t sa_len;
00049   u8_t sa_family;
00050   char sa_data[14];
00051 };
00052 
00053 #ifndef socklen_t
00054 #  define socklen_t int
00055 #endif
00056 
00057 
00058 #define SOCK_STREAM     1
00059 #define SOCK_DGRAM      2
00060 #define SOCK_RAW        3
00061 
00062 /*
00063  * Option flags per-socket.
00064  */
00065 #define SO_DEBUG        0x0001          /* turn on debugging info recording */
00066 #define SO_ACCEPTCONN   0x0002          /* socket has had listen() */
00067 #define SO_REUSEADDR    0x0004          /* allow local address reuse */
00068 #define SO_KEEPALIVE    0x0008          /* keep connections alive */
00069 #define SO_DONTROUTE    0x0010          /* just use interface addresses */
00070 #define SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
00071 #define SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
00072 #define SO_LINGER       0x0080          /* linger on close if data present */
00073 #define SO_OOBINLINE    0x0100          /* leave received OOB data in line */
00074 
00075 #define SO_DONTLINGER   (int)(~SO_LINGER)
00076 
00077 /*
00078  * Additional options, not kept in so_options.
00079  */
00080 #define SO_SNDBUF       0x1001          /* send buffer size */
00081 #define SO_RCVBUF       0x1002          /* receive buffer size */
00082 #define SO_SNDLOWAT     0x1003          /* send low-water mark */
00083 #define SO_RCVLOWAT     0x1004          /* receive low-water mark */
00084 #define SO_SNDTIMEO     0x1005          /* send timeout */
00085 #define SO_RCVTIMEO     0x1006          /* receive timeout */
00086 #define SO_ERROR        0x1007          /* get error status and clear */
00087 #define SO_TYPE         0x1008          /* get socket type */
00088 
00089 
00090 
00091 /*
00092  * Structure used for manipulating linger option.
00093  */
00094 struct linger {
00095        int l_onoff;                /* option on/off */
00096        int l_linger;               /* linger time */
00097 };
00098 
00099 /*
00100  * Level number for (get/set)sockopt() to apply to socket itself.
00101  */
00102 #define SOL_SOCKET      0xfff           /* options for socket level */
00103 
00104 
00105 #define AF_UNSPEC       0
00106 #define AF_INET         2
00107 #define PF_INET         AF_INET
00108 
00109 #define IPPROTO_TCP     6
00110 #define IPPROTO_UDP     17
00111 
00112 #define INADDR_ANY      0
00113 #define INADDR_BROADCAST 0xffffffff
00114 
00115 /* Flags we can use with send and recv. */
00116 #define MSG_DONTWAIT    0x40            /* Nonblocking i/o for this operation only */
00117 
00118 
00119 /*
00120  * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
00121  *
00122  *
00123  * Ioctl's have the command encoded in the lower word,
00124  * and the size of any in or out parameters in the upper
00125  * word.  The high 2 bits of the upper word are used
00126  * to encode the in/out status of the parameter; for now
00127  * we restrict parameters to at most 128 bytes.
00128  */
00129 #if !defined(FIONREAD) || !defined(FIONBIO)
00130 #define IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
00131 #define IOC_VOID        0x20000000      /* no parameters */
00132 #define IOC_OUT         0x40000000      /* copy out parameters */
00133 #define IOC_IN          0x80000000      /* copy in parameters */
00134 #define IOC_INOUT       (IOC_IN|IOC_OUT)
00135                                         /* 0x20000000 distinguishes new &
00136                                            old ioctl's */
00137 #define _IO(x,y)        (IOC_VOID|((x)<<8)|(y))
00138 
00139 #define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
00140 
00141 #define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
00142 #endif
00143 
00144 #ifndef FIONREAD
00145 #define FIONREAD    _IOR('f', 127, unsigned long) /* get # bytes to read */
00146 #endif
00147 #ifndef FIONBIO
00148 #define FIONBIO     _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
00149 #endif
00150 
00151 /* Socket I/O Controls */
00152 #ifndef SIOCSHIWAT
00153 #define SIOCSHIWAT  _IOW('s',  0, unsigned long)  /* set high watermark */
00154 #define SIOCGHIWAT  _IOR('s',  1, unsigned long)  /* get high watermark */
00155 #define SIOCSLOWAT  _IOW('s',  2, unsigned long)  /* set low watermark */
00156 #define SIOCGLOWAT  _IOR('s',  3, unsigned long)  /* get low watermark */
00157 #define SIOCATMARK  _IOR('s',  7, unsigned long)  /* at oob mark? */
00158 #endif
00159 
00160 #ifndef O_NONBLOCK
00161 #define O_NONBLOCK    04000
00162 #endif
00163 
00164 #ifndef FD_SET
00165   #undef  FD_SETSIZE
00166   #define FD_SETSIZE    16
00167   #define FD_SET(n, p)  ((p)->fd_bits[(n)/8] |=  (1 << ((n) & 7)))
00168   #define FD_CLR(n, p)  ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7)))
00169   #define FD_ISSET(n,p) ((p)->fd_bits[(n)/8] &   (1 << ((n) & 7)))
00170   #define FD_ZERO(p)    memset((void*)(p),0,sizeof(*(p)))
00171 
00172   typedef struct fd_set {
00173           unsigned char fd_bits [(FD_SETSIZE+7)/8];
00174         } fd_set;
00175 
00176   struct timeval {
00177           long    tv_sec;         /* seconds */
00178           long    tv_usec;        /* and microseconds */
00179   };
00180 
00181 #endif
00182 
00183 int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
00184 int lwip_bind(int s, struct sockaddr *name, socklen_t namelen);
00185 int lwip_shutdown(int s, int how);
00186 int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen);
00187 int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen);
00188 int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
00189 int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
00190 int lwip_close(int s);
00191 int lwip_connect(int s, struct sockaddr *name, socklen_t namelen);
00192 int lwip_listen(int s, int backlog);
00193 int lwip_recv(int s, void *mem, int len, unsigned int flags);
00194 int lwip_read(int s, void *mem, int len);
00195 int lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
00196                   struct sockaddr *from, socklen_t *fromlen);
00197 int lwip_send(int s, void *dataptr, int size, unsigned int flags);
00198 int lwip_sendto(int s, void *dataptr, int size, unsigned int flags,
00199                 struct sockaddr *to, socklen_t tolen);
00200 int lwip_socket(int domain, int type, int protocol);
00201 int lwip_write(int s, void *dataptr, int size);
00202 int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
00203                 struct timeval *timeout);
00204 int lwip_ioctl(int s, long cmd, void *argp);
00205 
00206 #if LWIP_COMPAT_SOCKETS
00207 #define accept(a,b,c)         lwip_accept(a,b,c)
00208 #define bind(a,b,c)           lwip_bind(a,b,c)
00209 #define shutdown(a,b)         lwip_shutdown(a,b)
00210 #define close(s)              lwip_close(s)
00211 #define connect(a,b,c)        lwip_connect(a,b,c)
00212 #define getsockname(a,b,c)    lwip_getsockname(a,b,c)
00213 #define getpeername(a,b,c)    lwip_getpeername(a,b,c)
00214 #define setsockopt(a,b,c,d,e) lwip_setsockopt(a,b,c,d,e)
00215 #define getsockopt(a,b,c,d,e) lwip_getsockopt(a,b,c,d,e)
00216 #define listen(a,b)           lwip_listen(a,b)
00217 #define recv(a,b,c,d)         lwip_recv(a,b,c,d)
00218 #define read(a,b,c)           lwip_read(a,b,c)
00219 #define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f)
00220 #define send(a,b,c,d)         lwip_send(a,b,c,d)
00221 #define sendto(a,b,c,d,e,f)   lwip_sendto(a,b,c,d,e,f)
00222 #define socket(a,b,c)         lwip_socket(a,b,c)
00223 #define write(a,b,c)          lwip_write(a,b,c)
00224 #define select(a,b,c,d,e)     lwip_select(a,b,c,d,e)
00225 #define ioctlsocket(a,b,c)     lwip_ioctl(a,b,c)
00226 #endif /* LWIP_COMPAT_SOCKETS */
00227 
00228 #endif /* __LWIP_SOCKETS_H__ */
00229 

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