]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/blob - src/include/lwip/sockets.h
New configuration option LWIP_IGMP to enable IGMP processing. Based on only one filte...
[pes-rpp/rpp-lwip.git] / src / include / lwip / sockets.h
1 /*
2  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3  * All rights reserved. 
4  * 
5  * Redistribution and use in source and binary forms, with or without modification, 
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  *    this list of conditions and the following disclaimer in the documentation
12  *    and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission. 
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
25  * OF SUCH DAMAGE.
26  *
27  * This file is part of the lwIP TCP/IP stack.
28  * 
29  * Author: Adam Dunkels <adam@sics.se>
30  *
31  */
32
33
34 #ifndef __LWIP_SOCKETS_H__
35 #define __LWIP_SOCKETS_H__
36 #include "lwip/ip_addr.h"
37 #include "opt.h"
38 #include "tcp.h"
39
40 struct sockaddr_in {
41   u8_t sin_len;
42   u8_t sin_family;
43   u16_t sin_port;
44   struct in_addr sin_addr;
45   char sin_zero[8];
46 };
47
48 struct sockaddr {
49   u8_t sa_len;
50   u8_t sa_family;
51   char sa_data[14];
52 };
53
54 #ifndef socklen_t
55 #  define socklen_t int
56 #endif
57
58
59 #define SOCK_STREAM     1
60 #define SOCK_DGRAM      2
61 #define SOCK_RAW        3
62
63 /*
64  * Option flags per-socket.
65  */
66 #define  SO_DEBUG       0x0001 /* turn on debugging info recording */
67 #define  SO_ACCEPTCONN  0x0002 /* socket has had listen() */
68 #define  SO_REUSEADDR   0x0004 /* allow local address reuse */
69 #define  SO_KEEPALIVE   0x0008 /* keep connections alive */
70 #define  SO_DONTROUTE   0x0010 /* just use interface addresses */
71 #define  SO_BROADCAST   0x0020 /* permit sending of broadcast msgs */
72 #define  SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
73 #define  SO_LINGER      0x0080 /* linger on close if data present */
74 #define  SO_OOBINLINE   0x0100 /* leave received OOB data in line */
75 #define  SO_REUSEPORT   0x0200 /* allow local address & port reuse */
76
77 #define SO_DONTLINGER   (int)(~SO_LINGER)
78
79 /*
80  * Additional options, not kept in so_options.
81  */
82 #define SO_SNDBUF    0x1001    /* send buffer size */
83 #define SO_RCVBUF    0x1002    /* receive buffer size */
84 #define SO_SNDLOWAT  0x1003    /* send low-water mark */
85 #define SO_RCVLOWAT  0x1004    /* receive low-water mark */
86 #define SO_SNDTIMEO  0x1005    /* send timeout */
87 #define SO_RCVTIMEO  0x1006    /* receive timeout */
88 #define SO_ERROR     0x1007    /* get error status and clear */
89 #define SO_TYPE      0x1008    /* get socket type */
90 #define SO_CONTIMEO  0x1009    /* connect timeout */
91
92
93 /*
94  * Structure used for manipulating linger option.
95  */
96 struct linger {
97        int l_onoff;                /* option on/off */
98        int l_linger;               /* linger time */
99 };
100
101 /*
102  * Level number for (get/set)sockopt() to apply to socket itself.
103  */
104 #define  SOL_SOCKET  0xfff    /* options for socket level */
105
106
107 #define AF_UNSPEC       0
108 #define AF_INET         2
109 #define PF_INET         AF_INET
110 #define PF_UNSPEC       AF_UNSPEC
111
112 #define IPPROTO_IP      0
113 #define IPPROTO_TCP     6
114 #define IPPROTO_UDP     17
115
116 #define INADDR_ANY      0
117 #define INADDR_BROADCAST 0xffffffff
118
119 /* Flags we can use with send and recv. */
120 #define MSG_DONTWAIT    0x40            /* Nonblocking i/o for this operation only */
121
122
123 /*
124  * Options for level IPPROTO_IP
125  */
126 #define IP_TOS             1
127 #define IP_TTL             2
128
129
130 #ifdef LWIP_IGMP
131 /*
132  * Options and types for UDP multicast traffic handling
133  */
134 #define IP_ADD_MEMBERSHIP  3
135 #define IP_DROP_MEMBERSHIP 4
136 #define IP_MULTICAST_TTL   5
137 #define IP_MULTICAST_IF    6
138 #define IP_MULTICAST_LOOP  7
139
140 typedef struct ip_mreq {
141     struct in_addr imr_multiaddr; /* IP multicast address of group */
142     struct in_addr imr_interface; /* local IP address of interface */
143 } ip_mreq;
144 #endif /* LWIP_IGMP */
145
146 #define IPTOS_TOS_MASK          0x1E
147 #define IPTOS_TOS(tos)          ((tos) & IPTOS_TOS_MASK)
148 #define IPTOS_LOWDELAY          0x10
149 #define IPTOS_THROUGHPUT        0x08
150 #define IPTOS_RELIABILITY       0x04
151 #define IPTOS_LOWCOST           0x02
152 #define IPTOS_MINCOST           IPTOS_LOWCOST
153
154 /*
155  * Definitions for IP precedence (also in ip_tos) (hopefully unused)
156  */
157 #define IPTOS_PREC_MASK                 0xe0
158 #define IPTOS_PREC(tos)                ((tos) & IPTOS_PREC_MASK)
159 #define IPTOS_PREC_NETCONTROL           0xe0
160 #define IPTOS_PREC_INTERNETCONTROL      0xc0
161 #define IPTOS_PREC_CRITIC_ECP           0xa0
162 #define IPTOS_PREC_FLASHOVERRIDE        0x80
163 #define IPTOS_PREC_FLASH                0x60
164 #define IPTOS_PREC_IMMEDIATE            0x40
165 #define IPTOS_PREC_PRIORITY             0x20
166 #define IPTOS_PREC_ROUTINE              0x00
167
168
169 /*
170  * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
171  *
172  *
173  * Ioctl's have the command encoded in the lower word,
174  * and the size of any in or out parameters in the upper
175  * word.  The high 2 bits of the upper word are used
176  * to encode the in/out status of the parameter; for now
177  * we restrict parameters to at most 128 bytes.
178  */
179 #if !defined(FIONREAD) || !defined(FIONBIO)
180 #define IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
181 #define IOC_VOID        0x20000000      /* no parameters */
182 #define IOC_OUT         0x40000000      /* copy out parameters */
183 #define IOC_IN          0x80000000      /* copy in parameters */
184 #define IOC_INOUT       (IOC_IN|IOC_OUT)
185                                         /* 0x20000000 distinguishes new &
186                                            old ioctl's */
187 #define _IO(x,y)        (IOC_VOID|((x)<<8)|(y))
188
189 #define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
190
191 #define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
192 #endif
193
194 #ifndef FIONREAD
195 #define FIONREAD    _IOR('f', 127, unsigned long) /* get # bytes to read */
196 #endif
197 #ifndef FIONBIO
198 #define FIONBIO     _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
199 #endif
200
201 /* Socket I/O Controls */
202 #ifndef SIOCSHIWAT
203 #define SIOCSHIWAT  _IOW('s',  0, unsigned long)  /* set high watermark */
204 #define SIOCGHIWAT  _IOR('s',  1, unsigned long)  /* get high watermark */
205 #define SIOCSLOWAT  _IOW('s',  2, unsigned long)  /* set low watermark */
206 #define SIOCGLOWAT  _IOR('s',  3, unsigned long)  /* get low watermark */
207 #define SIOCATMARK  _IOR('s',  7, unsigned long)  /* at oob mark? */
208 #endif
209
210 #ifndef O_NONBLOCK
211 #define O_NONBLOCK    04000U
212 #endif
213
214 #ifndef FD_SET
215   #undef  FD_SETSIZE
216   #define FD_SETSIZE    16
217   #define FD_SET(n, p)  ((p)->fd_bits[(n)/8] |=  (1 << ((n) & 7)))
218   #define FD_CLR(n, p)  ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7)))
219   #define FD_ISSET(n,p) ((p)->fd_bits[(n)/8] &   (1 << ((n) & 7)))
220   #define FD_ZERO(p)    memset((void*)(p),0,sizeof(*(p)))
221
222   typedef struct fd_set {
223           unsigned char fd_bits [(FD_SETSIZE+7)/8];
224         } fd_set;
225
226 /* 
227  * only define this in sockets.c so it does not interfere
228  * with other projects namespaces where timeval is present
229  */ 
230 #ifndef LWIP_TIMEVAL_PRIVATE
231 #define LWIP_TIMEVAL_PRIVATE 1
232 #endif
233
234 #if LWIP_TIMEVAL_PRIVATE
235   struct timeval {
236     long    tv_sec;         /* seconds */
237     long    tv_usec;        /* and microseconds */
238   };
239 #endif
240
241 #endif
242
243 void lwip_socket_init(void);
244
245 int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
246 int lwip_bind(int s, struct sockaddr *name, socklen_t namelen);
247 int lwip_shutdown(int s, int how);
248 int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen);
249 int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen);
250 int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
251 int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
252 int lwip_close(int s);
253 int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen);
254 int lwip_listen(int s, int backlog);
255 int lwip_recv(int s, void *mem, int len, unsigned int flags);
256 int lwip_read(int s, void *mem, int len);
257 int lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
258       struct sockaddr *from, socklen_t *fromlen);
259 int lwip_send(int s, const void *dataptr, int size, unsigned int flags);
260 int lwip_sendto(int s, const void *dataptr, int size, unsigned int flags,
261     struct sockaddr *to, socklen_t tolen);
262 int lwip_socket(int domain, int type, int protocol);
263 int lwip_write(int s, const void *dataptr, int size);
264 int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
265                 struct timeval *timeout);
266 int lwip_ioctl(int s, long cmd, void *argp);
267
268 #if LWIP_COMPAT_SOCKETS
269 #define accept(a,b,c)         lwip_accept(a,b,c)
270 #define bind(a,b,c)           lwip_bind(a,b,c)
271 #define shutdown(a,b)         lwip_shutdown(a,b)
272 #define closesocket(s)        lwip_close(s)
273 #define connect(a,b,c)        lwip_connect(a,b,c)
274 #define getsockname(a,b,c)    lwip_getsockname(a,b,c)
275 #define getpeername(a,b,c)    lwip_getpeername(a,b,c)
276 #define setsockopt(a,b,c,d,e) lwip_setsockopt(a,b,c,d,e)
277 #define getsockopt(a,b,c,d,e) lwip_getsockopt(a,b,c,d,e)
278 #define listen(a,b)           lwip_listen(a,b)
279 #define recv(a,b,c,d)         lwip_recv(a,b,c,d)
280 #define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f)
281 #define send(a,b,c,d)         lwip_send(a,b,c,d)
282 #define sendto(a,b,c,d,e,f)   lwip_sendto(a,b,c,d,e,f)
283 #define socket(a,b,c)         lwip_socket(a,b,c)
284 #define select(a,b,c,d,e)     lwip_select(a,b,c,d,e)
285 #define ioctlsocket(a,b,c)    lwip_ioctl(a,b,c)
286
287 #if LWIP_POSIX_SOCKETS_IO_NAMES
288 #define read(a,b,c)           lwip_read(a,b,c)
289 #define write(a,b,c)          lwip_write(a,b,c)
290 #define close(s)              lwip_close(s)
291 #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
292
293 #endif /* LWIP_COMPAT_SOCKETS */
294
295 #endif /* __LWIP_SOCKETS_H__ */
296