Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/lwip/sockets.h need to be fixed.

0001 /*
0002  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
0003  * All rights reserved. 
0004  * 
0005  * Redistribution and use in source and binary forms, with or without modification, 
0006  * are permitted provided that the following conditions are met:
0007  *
0008  * 1. Redistributions of source code must retain the above copyright notice,
0009  *    this list of conditions and the following disclaimer.
0010  * 2. Redistributions in binary form must reproduce the above copyright notice,
0011  *    this list of conditions and the following disclaimer in the documentation
0012  *    and/or other materials provided with the distribution.
0013  * 3. The name of the author may not be used to endorse or promote products
0014  *    derived from this software without specific prior written permission. 
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
0017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
0018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
0019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
0020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
0021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
0024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
0025  * OF SUCH DAMAGE.
0026  *
0027  * This file is part of the lwIP TCP/IP stack.
0028  * 
0029  * Author: Adam Dunkels <adam@sics.se>
0030  *
0031  */
0032 
0033 
0034 #ifndef __LWIP_SOCKETS_H__
0035 #define __LWIP_SOCKETS_H__
0036 
0037 #include "lwip/opt.h"
0038 
0039 #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
0040 
0041 #include <stddef.h>
0042 
0043 #include "lwip/ip_addr.h"
0044 #include "lwip/inet.h"
0045 
0046 #ifdef __cplusplus
0047 extern "C" {
0048 #endif
0049 
0050 /* members are in network byte order */
0051 struct sockaddr_in {
0052   u8_t sin_len;
0053   u8_t sin_family;
0054   u16_t sin_port;
0055   struct in_addr sin_addr;
0056   char sin_zero[8];
0057 };
0058 
0059 struct sockaddr {
0060   u8_t sa_len;
0061   u8_t sa_family;
0062   char sa_data[14];
0063 };
0064 
0065 #ifndef socklen_t
0066 #  define socklen_t u32_t
0067 #endif
0068 
0069 /* Socket protocol types (TCP/UDP/RAW) */
0070 #define SOCK_STREAM     1
0071 #define SOCK_DGRAM      2
0072 #define SOCK_RAW        3
0073 
0074 /*
0075  * Option flags per-socket. These must match the SOF_ flags in ip.h!
0076  */
0077 #define  SO_DEBUG       0x0001 /* Unimplemented: turn on debugging info recording */
0078 #define  SO_ACCEPTCONN  0x0002 /* socket has had listen() */
0079 #define  SO_REUSEADDR   0x0004 /* Unimplemented: allow local address reuse */
0080 #define  SO_KEEPALIVE   0x0008 /* keep connections alive */
0081 #define  SO_DONTROUTE   0x0010 /* Unimplemented: just use interface addresses */
0082 #define  SO_BROADCAST   0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
0083 #define  SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */
0084 #define  SO_LINGER      0x0080 /* linger on close if data present */
0085 #define  SO_OOBINLINE   0x0100 /* Unimplemented: leave received OOB data in line */
0086 #define  SO_REUSEPORT   0x0200 /* Unimplemented: allow local address & port reuse */
0087 
0088 #define SO_DONTLINGER   ((int)(~SO_LINGER))
0089 
0090 /*
0091  * Additional options, not kept in so_options.
0092  */
0093 #define SO_SNDBUF    0x1001    /* Unimplemented: send buffer size */
0094 #define SO_RCVBUF    0x1002    /* receive buffer size */
0095 #define SO_SNDLOWAT  0x1003    /* Unimplemented: send low-water mark */
0096 #define SO_RCVLOWAT  0x1004    /* Unimplemented: receive low-water mark */
0097 #define SO_SNDTIMEO  0x1005    /* Unimplemented: send timeout */
0098 #define SO_RCVTIMEO  0x1006    /* receive timeout */
0099 #define SO_ERROR     0x1007    /* get error status and clear */
0100 #define SO_TYPE      0x1008    /* get socket type */
0101 #define SO_CONTIMEO  0x1009    /* Unimplemented: connect timeout */
0102 #define SO_NO_CHECK  0x100a    /* don't create UDP checksum */
0103 
0104 
0105 /*
0106  * Structure used for manipulating linger option.
0107  */
0108 struct linger {
0109        int l_onoff;                /* option on/off */
0110        int l_linger;               /* linger time */
0111 };
0112 
0113 /*
0114  * Level number for (get/set)sockopt() to apply to socket itself.
0115  */
0116 #define  SOL_SOCKET  0xfff    /* options for socket level */
0117 
0118 
0119 #define AF_UNSPEC       0
0120 #define AF_INET         2
0121 #define PF_INET         AF_INET
0122 #define PF_UNSPEC       AF_UNSPEC
0123 
0124 #define IPPROTO_IP      0
0125 #define IPPROTO_TCP     6
0126 #define IPPROTO_UDP     17
0127 #define IPPROTO_UDPLITE 136
0128 
0129 /* Flags we can use with send and recv. */
0130 #define MSG_PEEK       0x01    /* Peeks at an incoming message */
0131 #define MSG_WAITALL    0x02    /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */
0132 #define MSG_OOB        0x04    /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */
0133 #define MSG_DONTWAIT   0x08    /* Nonblocking i/o for this operation only */
0134 #define MSG_MORE       0x10    /* Sender will send more */
0135 
0136 
0137 /*
0138  * Options for level IPPROTO_IP
0139  */
0140 #define IP_TOS             1
0141 #define IP_TTL             2
0142 
0143 #if LWIP_TCP
0144 /*
0145  * Options for level IPPROTO_TCP
0146  */
0147 #define TCP_NODELAY    0x01    /* don't delay send to coalesce packets */
0148 #define TCP_KEEPALIVE  0x02    /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */
0149 #define TCP_KEEPIDLE   0x03    /* set pcb->keep_idle  - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
0150 #define TCP_KEEPINTVL  0x04    /* set pcb->keep_intvl - Use seconds for get/setsockopt */
0151 #define TCP_KEEPCNT    0x05    /* set pcb->keep_cnt   - Use number of probes sent for get/setsockopt */
0152 #endif /* LWIP_TCP */
0153 
0154 #if LWIP_UDP && LWIP_UDPLITE
0155 /*
0156  * Options for level IPPROTO_UDPLITE
0157  */
0158 #define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */
0159 #define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */
0160 #endif /* LWIP_UDP && LWIP_UDPLITE*/
0161 
0162 
0163 #if LWIP_IGMP
0164 /*
0165  * Options and types for UDP multicast traffic handling
0166  */
0167 #define IP_ADD_MEMBERSHIP  3
0168 #define IP_DROP_MEMBERSHIP 4
0169 #define IP_MULTICAST_TTL   5
0170 #define IP_MULTICAST_IF    6
0171 #define IP_MULTICAST_LOOP  7
0172 
0173 typedef struct ip_mreq {
0174     struct in_addr imr_multiaddr; /* IP multicast address of group */
0175     struct in_addr imr_interface; /* local IP address of interface */
0176 } ip_mreq;
0177 #endif /* LWIP_IGMP */
0178 
0179 /*
0180  * The Type of Service provides an indication of the abstract
0181  * parameters of the quality of service desired.  These parameters are
0182  * to be used to guide the selection of the actual service parameters
0183  * when transmitting a datagram through a particular network.  Several
0184  * networks offer service precedence, which somehow treats high
0185  * precedence traffic as more important than other traffic (generally
0186  * by accepting only traffic above a certain precedence at time of high
0187  * load).  The major choice is a three way tradeoff between low-delay,
0188  * high-reliability, and high-throughput.
0189  * The use of the Delay, Throughput, and Reliability indications may
0190  * increase the cost (in some sense) of the service.  In many networks
0191  * better performance for one of these parameters is coupled with worse
0192  * performance on another.  Except for very unusual cases at most two
0193  * of these three indications should be set.
0194  */
0195 #define IPTOS_TOS_MASK          0x1E
0196 #define IPTOS_TOS(tos)          ((tos) & IPTOS_TOS_MASK)
0197 #define IPTOS_LOWDELAY          0x10
0198 #define IPTOS_THROUGHPUT        0x08
0199 #define IPTOS_RELIABILITY       0x04
0200 #define IPTOS_LOWCOST           0x02
0201 #define IPTOS_MINCOST           IPTOS_LOWCOST
0202 
0203 /*
0204  * The Network Control precedence designation is intended to be used
0205  * within a network only.  The actual use and control of that
0206  * designation is up to each network. The Internetwork Control
0207  * designation is intended for use by gateway control originators only.
0208  * If the actual use of these precedence designations is of concern to
0209  * a particular network, it is the responsibility of that network to
0210  * control the access to, and use of, those precedence designations.
0211  */
0212 #define IPTOS_PREC_MASK                 0xe0
0213 #define IPTOS_PREC(tos)                ((tos) & IPTOS_PREC_MASK)
0214 #define IPTOS_PREC_NETCONTROL           0xe0
0215 #define IPTOS_PREC_INTERNETCONTROL      0xc0
0216 #define IPTOS_PREC_CRITIC_ECP           0xa0
0217 #define IPTOS_PREC_FLASHOVERRIDE        0x80
0218 #define IPTOS_PREC_FLASH                0x60
0219 #define IPTOS_PREC_IMMEDIATE            0x40
0220 #define IPTOS_PREC_PRIORITY             0x20
0221 #define IPTOS_PREC_ROUTINE              0x00
0222 
0223 
0224 /*
0225  * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
0226  * lwip_ioctl only supports FIONREAD and FIONBIO, for now
0227  *
0228  * Ioctl's have the command encoded in the lower word,
0229  * and the size of any in or out parameters in the upper
0230  * word.  The high 2 bits of the upper word are used
0231  * to encode the in/out status of the parameter; for now
0232  * we restrict parameters to at most 128 bytes.
0233  */
0234 #if !defined(FIONREAD) || !defined(FIONBIO)
0235 #define IOCPARM_MASK    0x7fU           /* parameters must be < 128 bytes */
0236 #define IOC_VOID        0x20000000UL    /* no parameters */
0237 #define IOC_OUT         0x40000000UL    /* copy out parameters */
0238 #define IOC_IN          0x80000000UL    /* copy in parameters */
0239 #define IOC_INOUT       (IOC_IN|IOC_OUT)
0240                                         /* 0x20000000 distinguishes new &
0241                                            old ioctl's */
0242 #define _IO(x,y)        (IOC_VOID|((x)<<8)|(y))
0243 
0244 #define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
0245 
0246 #define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
0247 #endif /* !defined(FIONREAD) || !defined(FIONBIO) */
0248 
0249 #ifndef FIONREAD
0250 #define FIONREAD    _IOR('f', 127, unsigned long) /* get # bytes to read */
0251 #endif
0252 #ifndef FIONBIO
0253 #define FIONBIO     _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
0254 #endif
0255 
0256 /* Socket I/O Controls: unimplemented */
0257 #ifndef SIOCSHIWAT
0258 #define SIOCSHIWAT  _IOW('s',  0, unsigned long)  /* set high watermark */
0259 #define SIOCGHIWAT  _IOR('s',  1, unsigned long)  /* get high watermark */
0260 #define SIOCSLOWAT  _IOW('s',  2, unsigned long)  /* set low watermark */
0261 #define SIOCGLOWAT  _IOR('s',  3, unsigned long)  /* get low watermark */
0262 #define SIOCATMARK  _IOR('s',  7, unsigned long)  /* at oob mark? */
0263 #endif
0264 
0265 /* Socket flags: */
0266 #ifndef O_NONBLOCK
0267 #define O_NONBLOCK    04000U
0268 #endif
0269 
0270 /* FD_SET used for lwip_select */
0271 #ifndef FD_SET
0272   #undef  FD_SETSIZE
0273   /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */
0274   #define FD_SETSIZE    MEMP_NUM_NETCONN
0275   #define FD_SET(n, p)  ((p)->fd_bits[(n)/8] |=  (1 << ((n) & 7)))
0276   #define FD_CLR(n, p)  ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7)))
0277   #define FD_ISSET(n,p) ((p)->fd_bits[(n)/8] &   (1 << ((n) & 7)))
0278   #define FD_ZERO(p)    memset((void*)(p),0,sizeof(*(p)))
0279 
0280   typedef struct fd_set {
0281           unsigned char fd_bits [(FD_SETSIZE+7)/8];
0282         } fd_set;
0283 
0284 #endif /* FD_SET */
0285 
0286 /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
0287  * by your system, set this to 0 and include <sys/time.h> in cc.h */ 
0288 #ifndef LWIP_TIMEVAL_PRIVATE
0289 #define LWIP_TIMEVAL_PRIVATE 1
0290 #endif
0291 
0292 #if LWIP_TIMEVAL_PRIVATE
0293 struct timeval {
0294   long    tv_sec;         /* seconds */
0295   long    tv_usec;        /* and microseconds */
0296 };
0297 #endif /* LWIP_TIMEVAL_PRIVATE */
0298 
0299 void lwip_socket_init(void);
0300 
0301 int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
0302 int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen);
0303 int lwip_shutdown(int s, int how);
0304 int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen);
0305 int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen);
0306 int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
0307 int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
0308 int lwip_close(int s);
0309 int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen);
0310 int lwip_listen(int s, int backlog);
0311 int lwip_recv(int s, void *mem, size_t len, int flags);
0312 int lwip_read(int s, void *mem, size_t len);
0313 int lwip_recvfrom(int s, void *mem, size_t len, int flags,
0314       struct sockaddr *from, socklen_t *fromlen);
0315 int lwip_send(int s, const void *dataptr, size_t size, int flags);
0316 int lwip_sendto(int s, const void *dataptr, size_t size, int flags,
0317     const struct sockaddr *to, socklen_t tolen);
0318 int lwip_socket(int domain, int type, int protocol);
0319 int lwip_write(int s, const void *dataptr, size_t size);
0320 int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
0321                 struct timeval *timeout);
0322 int lwip_ioctl(int s, long cmd, void *argp);
0323 
0324 #if LWIP_COMPAT_SOCKETS
0325 #define accept(a,b,c)         lwip_accept(a,b,c)
0326 #define bind(a,b,c)           lwip_bind(a,b,c)
0327 #define shutdown(a,b)         lwip_shutdown(a,b)
0328 #define closesocket(s)        lwip_close(s)
0329 #define connect(a,b,c)        lwip_connect(a,b,c)
0330 #define getsockname(a,b,c)    lwip_getsockname(a,b,c)
0331 #define getpeername(a,b,c)    lwip_getpeername(a,b,c)
0332 #define setsockopt(a,b,c,d,e) lwip_setsockopt(a,b,c,d,e)
0333 #define getsockopt(a,b,c,d,e) lwip_getsockopt(a,b,c,d,e)
0334 #define listen(a,b)           lwip_listen(a,b)
0335 #define recv(a,b,c,d)         lwip_recv(a,b,c,d)
0336 #define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f)
0337 #define send(a,b,c,d)         lwip_send(a,b,c,d)
0338 #define sendto(a,b,c,d,e,f)   lwip_sendto(a,b,c,d,e,f)
0339 #define socket(a,b,c)         lwip_socket(a,b,c)
0340 #define select(a,b,c,d,e)     lwip_select(a,b,c,d,e)
0341 #define ioctlsocket(a,b,c)    lwip_ioctl(a,b,c)
0342 
0343 #if LWIP_POSIX_SOCKETS_IO_NAMES
0344 #define read(a,b,c)           lwip_read(a,b,c)
0345 #define write(a,b,c)          lwip_write(a,b,c)
0346 #define close(s)              lwip_close(s)
0347 #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
0348 
0349 #endif /* LWIP_COMPAT_SOCKETS */
0350 
0351 #ifdef __cplusplus
0352 }
0353 #endif
0354 
0355 #endif /* LWIP_SOCKET */
0356 
0357 #endif /* __LWIP_SOCKETS_H__ */