]> granicus.if.org Git - esp-idf/blob - components/lwip/include/lwip/lwip/sockets.h
Initial public version
[esp-idf] / components / lwip / include / lwip / 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_HDR_SOCKETS_H
35 #define LWIP_HDR_SOCKETS_H
36
37 #include "lwip/opt.h"
38
39 #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
40
41 #include <stddef.h> /* for size_t */
42
43 #include "lwip/ip_addr.h"
44 #include "lwip/err.h"
45 #include "lwip/inet.h"
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 /* If your port already typedef's sa_family_t, define SA_FAMILY_T_DEFINED
52    to prevent this code from redefining it. */
53 #if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED)
54 typedef u8_t sa_family_t;
55 #endif
56 /* If your port already typedef's in_port_t, define IN_PORT_T_DEFINED
57    to prevent this code from redefining it. */
58 #if !defined(in_port_t) && !defined(IN_PORT_T_DEFINED)
59 typedef u16_t in_port_t;
60 #endif
61
62 #if LWIP_IPV4
63 /* members are in network byte order */
64 struct sockaddr_in {
65   u8_t            sin_len;
66   sa_family_t     sin_family;
67   in_port_t       sin_port;
68   struct in_addr  sin_addr;
69 #define SIN_ZERO_LEN 8
70   char            sin_zero[SIN_ZERO_LEN];
71 };
72 #endif /* LWIP_IPV4 */
73
74 #if LWIP_IPV6
75 struct sockaddr_in6 {
76   u8_t            sin6_len;      /* length of this structure    */
77   sa_family_t     sin6_family;   /* AF_INET6                    */
78   in_port_t       sin6_port;     /* Transport layer port #      */
79   u32_t           sin6_flowinfo; /* IPv6 flow information       */
80   struct in6_addr sin6_addr;     /* IPv6 address                */
81   u32_t           sin6_scope_id; /* Set of interfaces for scope */
82 };
83 #endif /* LWIP_IPV6 */
84
85 struct sockaddr {
86   u8_t        sa_len;
87   sa_family_t sa_family;
88   char        sa_data[14];
89 };
90
91 struct sockaddr_storage {
92   u8_t        s2_len;
93   sa_family_t ss_family;
94   char        s2_data1[2];
95   u32_t       s2_data2[3];
96 #if LWIP_IPV6
97   u32_t       s2_data3[3];
98 #endif /* LWIP_IPV6 */
99 };
100
101 /* If your port already typedef's socklen_t, define SOCKLEN_T_DEFINED
102    to prevent this code from redefining it. */
103 #if !defined(socklen_t) && !defined(SOCKLEN_T_DEFINED)
104 typedef u32_t socklen_t;
105 #endif
106
107 struct lwip_sock;
108
109 #if !LWIP_TCPIP_CORE_LOCKING
110 /** Maximum optlen used by setsockopt/getsockopt */
111 #define LWIP_SETGETSOCKOPT_MAXOPTLEN 16
112
113 /** This struct is used to pass data to the set/getsockopt_internal
114  * functions running in tcpip_thread context (only a void* is allowed) */
115 struct lwip_setgetsockopt_data {
116   /** socket index for which to change options */
117   int s;
118   /** level of the option to process */
119   int level;
120   /** name of the option to process */
121   int optname;
122   /** set: value to set the option to
123     * get: value of the option is stored here */
124 #if LWIP_MPU_COMPATIBLE
125   u8_t optval[LWIP_SETGETSOCKOPT_MAXOPTLEN];
126 #else
127   union {
128      void *p;
129      const void *pc;
130   } optval;
131 #endif
132   /** size of *optval */
133   socklen_t optlen;
134   /** if an error occurs, it is temporarily stored here */
135   err_t err;
136   /** semaphore to wake up the calling task */
137   void* completed_sem;
138 };
139 #endif /* !LWIP_TCPIP_CORE_LOCKING */
140
141 #if !defined(iovec)
142 struct iovec {
143   void  *iov_base;
144   size_t iov_len;
145 };
146 #endif
147
148 struct msghdr {
149   void         *msg_name;
150   socklen_t     msg_namelen;
151   struct iovec *msg_iov;
152   int           msg_iovlen;
153   void         *msg_control;
154   socklen_t     msg_controllen;
155   int           msg_flags;
156 };
157
158 /* Socket protocol types (TCP/UDP/RAW) */
159 #define SOCK_STREAM     1
160 #define SOCK_DGRAM      2
161 #define SOCK_RAW        3
162
163 /*
164  * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c)
165  */
166 #define SO_REUSEADDR   0x0004 /* Allow local address reuse */
167 #define SO_KEEPALIVE   0x0008 /* keep connections alive */
168 #define SO_BROADCAST   0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
169
170
171 /*
172  * Additional options, not kept in so_options.
173  */
174 #define SO_DEBUG       0x0001 /* Unimplemented: turn on debugging info recording */
175 #define SO_ACCEPTCONN  0x0002 /* socket has had listen() */
176 #define SO_DONTROUTE   0x0010 /* Unimplemented: just use interface addresses */
177 #define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */
178 #define SO_LINGER      0x0080 /* linger on close if data present */
179 #define SO_DONTLINGER  ((int)(~SO_LINGER))
180 #define SO_OOBINLINE   0x0100 /* Unimplemented: leave received OOB data in line */
181 #define SO_REUSEPORT   0x0200 /* Unimplemented: allow local address & port reuse */
182 #define SO_SNDBUF      0x1001 /* Unimplemented: send buffer size */
183 #define SO_RCVBUF      0x1002 /* receive buffer size */
184 #define SO_SNDLOWAT    0x1003 /* Unimplemented: send low-water mark */
185 #define SO_RCVLOWAT    0x1004 /* Unimplemented: receive low-water mark */
186 #define SO_SNDTIMEO    0x1005 /* send timeout */
187 #define SO_RCVTIMEO    0x1006 /* receive timeout */
188 #define SO_ERROR       0x1007 /* get error status and clear */
189 #define SO_TYPE        0x1008 /* get socket type */
190 #define SO_CONTIMEO    0x1009 /* Unimplemented: connect timeout */
191 #define SO_NO_CHECK    0x100a /* don't create UDP checksum */
192
193
194 /*
195  * Structure used for manipulating linger option.
196  */
197 struct linger {
198        int l_onoff;                /* option on/off */
199        int l_linger;               /* linger time in seconds */
200 };
201
202 /*
203  * Level number for (get/set)sockopt() to apply to socket itself.
204  */
205 #define  SOL_SOCKET  0xfff    /* options for socket level */
206
207
208 #define AF_UNSPEC       0
209 #define AF_INET         2
210 #if LWIP_IPV6
211 #define AF_INET6        10
212 #else /* LWIP_IPV6 */
213 #define AF_INET6        AF_UNSPEC
214 #endif /* LWIP_IPV6 */
215 #define PF_INET         AF_INET
216 #define PF_INET6        AF_INET6
217 #define PF_UNSPEC       AF_UNSPEC
218
219 #define IPPROTO_IP      0
220 #define IPPROTO_ICMP    1
221 #define IPPROTO_TCP     6
222 #define IPPROTO_UDP     17
223 #if LWIP_IPV6
224 #define IPPROTO_IPV6    41
225 #define IPPROTO_ICMPV6  58
226 #endif /* LWIP_IPV6 */
227 #define IPPROTO_UDPLITE 136
228 #define IPPROTO_RAW     255
229
230 /* Flags we can use with send and recv. */
231 #define MSG_PEEK       0x01    /* Peeks at an incoming message */
232 #define MSG_WAITALL    0x02    /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */
233 #define MSG_OOB        0x04    /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */
234 #define MSG_DONTWAIT   0x08    /* Nonblocking i/o for this operation only */
235 #define MSG_MORE       0x10    /* Sender will send more */
236
237
238 /*
239  * Options for level IPPROTO_IP
240  */
241 #define IP_TOS             1
242 #define IP_TTL             2
243
244 #if LWIP_TCP
245 /*
246  * Options for level IPPROTO_TCP
247  */
248 #define TCP_NODELAY    0x01    /* don't delay send to coalesce packets */
249 #define TCP_KEEPALIVE  0x02    /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */
250 #define TCP_KEEPIDLE   0x03    /* set pcb->keep_idle  - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
251 #define TCP_KEEPINTVL  0x04    /* set pcb->keep_intvl - Use seconds for get/setsockopt */
252 #define TCP_KEEPCNT    0x05    /* set pcb->keep_cnt   - Use number of probes sent for get/setsockopt */
253 #endif /* LWIP_TCP */
254
255 #if LWIP_IPV6
256 /*
257  * Options for level IPPROTO_IPV6
258  */
259 #define IPV6_CHECKSUM       7  /* RFC3542: calculate and insert the ICMPv6 checksum for raw sockets. */
260 #define IPV6_V6ONLY         27 /* RFC3493: boolean control to restrict AF_INET6 sockets to IPv6 communications only. */
261 #endif /* LWIP_IPV6 */
262
263 #if LWIP_UDP && LWIP_UDPLITE
264 /*
265  * Options for level IPPROTO_UDPLITE
266  */
267 #define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */
268 #define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */
269 #endif /* LWIP_UDP && LWIP_UDPLITE*/
270
271
272 #if LWIP_MULTICAST_TX_OPTIONS
273 /*
274  * Options and types for UDP multicast traffic handling
275  */
276 #define IP_MULTICAST_TTL   5
277 #define IP_MULTICAST_IF    6
278 #define IP_MULTICAST_LOOP  7
279 #endif /* LWIP_MULTICAST_TX_OPTIONS */
280
281 #if LWIP_IGMP
282 /*
283  * Options and types related to multicast membership
284  */
285 #define IP_ADD_MEMBERSHIP  3
286 #define IP_DROP_MEMBERSHIP 4
287
288 typedef struct ip_mreq {
289     struct in_addr imr_multiaddr; /* IP multicast address of group */
290     struct in_addr imr_interface; /* local IP address of interface */
291 } ip_mreq;
292 #endif /* LWIP_IGMP */
293
294 /*
295  * The Type of Service provides an indication of the abstract
296  * parameters of the quality of service desired.  These parameters are
297  * to be used to guide the selection of the actual service parameters
298  * when transmitting a datagram through a particular network.  Several
299  * networks offer service precedence, which somehow treats high
300  * precedence traffic as more important than other traffic (generally
301  * by accepting only traffic above a certain precedence at time of high
302  * load).  The major choice is a three way tradeoff between low-delay,
303  * high-reliability, and high-throughput.
304  * The use of the Delay, Throughput, and Reliability indications may
305  * increase the cost (in some sense) of the service.  In many networks
306  * better performance for one of these parameters is coupled with worse
307  * performance on another.  Except for very unusual cases at most two
308  * of these three indications should be set.
309  */
310 #define IPTOS_TOS_MASK          0x1E
311 #define IPTOS_TOS(tos)          ((tos) & IPTOS_TOS_MASK)
312 #define IPTOS_LOWDELAY          0x10
313 #define IPTOS_THROUGHPUT        0x08
314 #define IPTOS_RELIABILITY       0x04
315 #define IPTOS_LOWCOST           0x02
316 #define IPTOS_MINCOST           IPTOS_LOWCOST
317
318 /*
319  * The Network Control precedence designation is intended to be used
320  * within a network only.  The actual use and control of that
321  * designation is up to each network. The Internetwork Control
322  * designation is intended for use by gateway control originators only.
323  * If the actual use of these precedence designations is of concern to
324  * a particular network, it is the responsibility of that network to
325  * control the access to, and use of, those precedence designations.
326  */
327 #define IPTOS_PREC_MASK                 0xe0
328 #define IPTOS_PREC(tos)                ((tos) & IPTOS_PREC_MASK)
329 #define IPTOS_PREC_NETCONTROL           0xe0
330 #define IPTOS_PREC_INTERNETCONTROL      0xc0
331 #define IPTOS_PREC_CRITIC_ECP           0xa0
332 #define IPTOS_PREC_FLASHOVERRIDE        0x80
333 #define IPTOS_PREC_FLASH                0x60
334 #define IPTOS_PREC_IMMEDIATE            0x40
335 #define IPTOS_PREC_PRIORITY             0x20
336 #define IPTOS_PREC_ROUTINE              0x00
337
338
339 /*
340  * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
341  * lwip_ioctl only supports FIONREAD and FIONBIO, for now
342  *
343  * Ioctl's have the command encoded in the lower word,
344  * and the size of any in or out parameters in the upper
345  * word.  The high 2 bits of the upper word are used
346  * to encode the in/out status of the parameter; for now
347  * we restrict parameters to at most 128 bytes.
348  */
349 #if !defined(FIONREAD) || !defined(FIONBIO)
350 #define IOCPARM_MASK    0x7fU           /* parameters must be < 128 bytes */
351 #define IOC_VOID        0x20000000UL    /* no parameters */
352 #define IOC_OUT         0x40000000UL    /* copy out parameters */
353 #define IOC_IN          0x80000000UL    /* copy in parameters */
354 #define IOC_INOUT       (IOC_IN|IOC_OUT)
355                                         /* 0x20000000 distinguishes new &
356                                            old ioctl's */
357 #define _IO(x,y)        (IOC_VOID|((x)<<8)|(y))
358
359 #define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
360
361 #define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
362 #endif /* !defined(FIONREAD) || !defined(FIONBIO) */
363
364 #ifndef FIONREAD
365 #define FIONREAD    _IOR('f', 127, unsigned long) /* get # bytes to read */
366 #endif
367 #ifndef FIONBIO
368 #define FIONBIO     _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
369 #endif
370
371 /* Socket I/O Controls: unimplemented */
372 #ifndef SIOCSHIWAT
373 #define SIOCSHIWAT  _IOW('s',  0, unsigned long)  /* set high watermark */
374 #define SIOCGHIWAT  _IOR('s',  1, unsigned long)  /* get high watermark */
375 #define SIOCSLOWAT  _IOW('s',  2, unsigned long)  /* set low watermark */
376 #define SIOCGLOWAT  _IOR('s',  3, unsigned long)  /* get low watermark */
377 #define SIOCATMARK  _IOR('s',  7, unsigned long)  /* at oob mark? */
378 #endif
379
380 /* commands for fnctl */
381 #ifndef F_GETFL
382 #define F_GETFL 3
383 #endif
384 #ifndef F_SETFL
385 #define F_SETFL 4
386 #endif
387
388 /* File status flags and file access modes for fnctl,
389    these are bits in an int. */
390 #ifndef O_NONBLOCK
391 #define O_NONBLOCK  1 /* nonblocking I/O */
392 #endif
393 #ifndef O_NDELAY
394 #define O_NDELAY    1 /* same as O_NONBLOCK, for compatibility */
395 #endif
396
397 #ifndef SHUT_RD
398   #define SHUT_RD   0
399   #define SHUT_WR   1
400   #define SHUT_RDWR 2
401 #endif
402
403 /* FD_SET used for lwip_select */
404 #ifndef FD_SET
405 #undef  FD_SETSIZE
406 /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */
407 #define FD_SETSIZE    MEMP_NUM_NETCONN
408 #define FDSETSAFESET(n, code) do { \
409   if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \
410   code; }} while(0)
411 #define FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\
412   (code) : 0)
413 #define FD_SET(n, p)  FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] |=  (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
414 #define FD_CLR(n, p)  FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] &= ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
415 #define FD_ISSET(n,p) FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] &   (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
416 #define FD_ZERO(p)    memset((void*)(p), 0, sizeof(*(p)))
417
418 typedef struct fd_set
419 {
420   unsigned char fd_bits [(FD_SETSIZE+7)/8];
421 } fd_set;
422
423 #elif LWIP_SOCKET_OFFSET
424 #error LWIP_SOCKET_OFFSET does not work with external FD_SET!
425 #endif /* FD_SET */
426
427 /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
428  * by your system, set this to 0 and include <sys/time.h> in cc.h */
429 #ifndef LWIP_TIMEVAL_PRIVATE
430 #define LWIP_TIMEVAL_PRIVATE 1
431 #endif
432
433 #if LWIP_TIMEVAL_PRIVATE
434 struct timeval {
435   long    tv_sec;         /* seconds */
436   long    tv_usec;        /* and microseconds */
437 };
438 #endif /* LWIP_TIMEVAL_PRIVATE */
439
440 #define lwip_socket_init() /* Compatibility define, no init needed. */
441 void lwip_socket_thread_init(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: initialize thread-local semaphore */
442 void lwip_socket_thread_cleanup(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: destroy thread-local semaphore */
443
444 #if LWIP_COMPAT_SOCKETS == 2
445
446
447 /* This helps code parsers/code completion by not having the COMPAT functions as defines */
448 #define lwip_accept       accept
449 #define lwip_bind         bind
450 #define lwip_shutdown     shutdown
451 #define lwip_getpeername  getpeername
452 #define lwip_getsockname  getsockname
453 #define lwip_setsockopt   setsockopt
454 #define lwip_getsockopt   getsockopt
455 #define lwip_close        closesocket
456 #define lwip_connect      connect
457 #define lwip_listen       listen
458 #define lwip_recv         recv
459 #define lwip_recvfrom     recvfrom
460 #define lwip_send         send
461 #define lwip_sendmsg      sendmsg
462 #define lwip_sendto       sendto
463 #define lwip_socket       socket
464 #define lwip_select       select
465 #define lwip_ioctlsocket  ioctl
466
467 #if LWIP_POSIX_SOCKETS_IO_NAMES
468 #define lwip_read         read
469 #define lwip_write        write
470 #define lwip_writev       writev
471 #undef lwip_close
472 #define lwip_close        close
473 #define closesocket(s)    close(s)
474 #define lwip_fcntl        fcntl
475 #define lwip_ioctl        ioctl
476 #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
477 #endif /* LWIP_COMPAT_SOCKETS == 2 */
478
479 int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
480 int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen);
481 int lwip_shutdown(int s, int how);
482 int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen);
483 int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen);
484 int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
485 int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
486 int lwip_close(int s);
487 int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen);
488 int lwip_listen(int s, int backlog);
489 int lwip_recv(int s, void *mem, size_t len, int flags);
490 int lwip_read(int s, void *mem, size_t len);
491 int lwip_recvfrom(int s, void *mem, size_t len, int flags,
492       struct sockaddr *from, socklen_t *fromlen);
493 int lwip_send(int s, const void *dataptr, size_t size, int flags);
494 int lwip_sendmsg(int s, const struct msghdr *message, int flags);
495 int lwip_sendto(int s, const void *dataptr, size_t size, int flags,
496     const struct sockaddr *to, socklen_t tolen);
497 int lwip_socket(int domain, int type, int protocol);
498 int lwip_write(int s, const void *dataptr, size_t size);
499 int lwip_writev(int s, const struct iovec *iov, int iovcnt);
500 int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
501                 struct timeval *timeout);
502 int lwip_ioctl(int s, long cmd, void *argp);
503 int lwip_fcntl(int s, int cmd, int val);
504
505 #if LWIP_COMPAT_SOCKETS
506 #if LWIP_COMPAT_SOCKETS != 2
507
508 #ifdef LWIP_THREAD_SAFE
509
510 int lwip_accept_r(int s, struct sockaddr *addr, socklen_t *addrlen);
511 int lwip_bind_r(int s, const struct sockaddr *name, socklen_t namelen);
512 int lwip_shutdown_r(int s, int how);
513 int lwip_getpeername_r (int s, struct sockaddr *name, socklen_t *namelen);
514 int lwip_getsockname_r (int s, struct sockaddr *name, socklen_t *namelen);
515 int lwip_getsockopt_r (int s, int level, int optname, void *optval, socklen_t *optlen);
516 int lwip_setsockopt_r (int s, int level, int optname, const void *optval, socklen_t optlen);
517 int lwip_close_r(int s);
518 int lwip_connect_r(int s, const struct sockaddr *name, socklen_t namelen);
519 int lwip_listen_r(int s, int backlog);
520 int lwip_recv_r(int s, void *mem, size_t len, int flags);
521 int lwip_read_r(int s, void *mem, size_t len); 
522 int lwip_recvfrom_r(int s, void *mem, size_t len, int flags,
523       struct sockaddr *from, socklen_t *fromlen);
524 int lwip_send_r(int s, const void *dataptr, size_t size, int flags);
525 int lwip_sendmsg_r(int s, const struct msghdr *message, int flags);
526 int lwip_sendto_r(int s, const void *dataptr, size_t size, int flags,
527     const struct sockaddr *to, socklen_t tolen);
528 int lwip_socket(int domain, int type, int protocol);
529 int lwip_write_r(int s, const void *dataptr, size_t size);
530 int lwip_writev_r(int s, const struct iovec *iov, int iovcnt);
531 int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
532                 struct timeval *timeout);
533 int lwip_ioctl_r(int s, long cmd, void *argp);
534 int lwip_fcntl_r(int s, int cmd, int val);
535
536 #define accept(s,addr,addrlen)                    lwip_accept_r(s,addr,addrlen)
537 #define bind(s,name,namelen)                      lwip_bind_r(s,name,namelen)
538 #define shutdown(s,how)                           lwip_shutdown_r(s,how)
539 #define getpeername(s,name,namelen)               lwip_getpeername_r(s,name,namelen)
540 #define getsockname(s,name,namelen)               lwip_getsockname_r(s,name,namelen)
541 #define setsockopt(s,level,optname,opval,optlen)  lwip_setsockopt_r(s,level,optname,opval,optlen)
542 #define getsockopt(s,level,optname,opval,optlen)  lwip_getsockopt_r(s,level,optname,opval,optlen)
543 #define closesocket(s)                            lwip_close_r(s)
544 #define connect(s,name,namelen)                   lwip_connect_r(s,name,namelen)
545 #define listen(s,backlog)                         lwip_listen_r(s,backlog)
546 #define recv(s,mem,len,flags)                     lwip_recv_r(s,mem,len,flags)
547 #define recvfrom(s,mem,len,flags,from,fromlen)    lwip_recvfrom_r(s,mem,len,flags,from,fromlen)
548 #define send(s,dataptr,size,flags)                lwip_send_r(s,dataptr,size,flags)
549 #define sendmsg(s,message,flags)                  lwip_sendmsg_r(s,message,flags)
550 #define sendto(s,dataptr,size,flags,to,tolen)     lwip_sendto_r(s,dataptr,size,flags,to,tolen)
551 #define socket(domain,type,protocol)              lwip_socket(domain,type,protocol)
552 #define select(maxfdp1,readset,writeset,exceptset,timeout)     lwip_select(maxfdp1,readset,writeset,exceptset,timeout)
553 #define ioctlsocket(s,cmd,argp)                   lwip_ioctl_r(s,cmd,argp)
554
555 #if LWIP_POSIX_SOCKETS_IO_NAMES
556 #define read(s,mem,len)                           lwip_read_r(s,mem,len)
557 #define write(s,dataptr,len)                      lwip_write_r(s,dataptr,len)
558 #define writev(s,iov,iovcnt)                      lwip_writev_r(s,iov,iovcnt)
559 #define close(s)                                  lwip_close_r(s)
560 #define fcntl(s,cmd,val)                          lwip_fcntl_r(s,cmd,val)
561 #define ioctl(s,cmd,argp)                         lwip_ioctl_r(s,cmd,argp)
562 #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
563
564 #else
565
566 #define accept(s,addr,addrlen)                    lwip_accept(s,addr,addrlen)
567 #define bind(s,name,namelen)                      lwip_bind(s,name,namelen)
568 #define shutdown(s,how)                           lwip_shutdown(s,how)
569 #define getpeername(s,name,namelen)               lwip_getpeername(s,name,namelen)
570 #define getsockname(s,name,namelen)               lwip_getsockname(s,name,namelen)
571 #define setsockopt(s,level,optname,opval,optlen)  lwip_setsockopt(s,level,optname,opval,optlen)
572 #define getsockopt(s,level,optname,opval,optlen)  lwip_getsockopt(s,level,optname,opval,optlen)
573 #define closesocket(s)                            lwip_close(s)
574 #define connect(s,name,namelen)                   lwip_connect(s,name,namelen)
575 #define listen(s,backlog)                         lwip_listen(s,backlog)
576 #define recv(s,mem,len,flags)                     lwip_recv(s,mem,len,flags)
577 #define recvfrom(s,mem,len,flags,from,fromlen)    lwip_recvfrom(s,mem,len,flags,from,fromlen)
578 #define send(s,dataptr,size,flags)                lwip_send(s,dataptr,size,flags)
579 #define sendmsg(s,message,flags)                  lwip_sendmsg(s,message,flags)
580 #define sendto(s,dataptr,size,flags,to,tolen)     lwip_sendto(s,dataptr,size,flags,to,tolen)
581 #define socket(domain,type,protocol)              lwip_socket(domain,type,protocol)
582 #define select(maxfdp1,readset,writeset,exceptset,timeout)     lwip_select(maxfdp1,readset,writeset,exceptset,timeout)
583 #define ioctlsocket(s,cmd,argp)                   lwip_ioctl(s,cmd,argp)
584
585 #if LWIP_POSIX_SOCKETS_IO_NAMES
586 #define read(s,mem,len)                           lwip_read(s,mem,len)
587 #define write(s,dataptr,len)                      lwip_write(s,dataptr,len)
588 #define writev(s,iov,iovcnt)                      lwip_writev(s,iov,iovcnt)
589 #define close(s)                                  lwip_close(s)
590 #define fcntl(s,cmd,val)                          lwip_fcntl(s,cmd,val)
591 #define ioctl(s,cmd,argp)                         lwip_ioctl(s,cmd,argp)
592 #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
593 #endif /* LWIP_THREAD_SAFE */
594
595 #endif /* LWIP_COMPAT_SOCKETS != 2 */
596
597 #if LWIP_IPV4 && LWIP_IPV6
598 #define inet_ntop(af,src,dst,size) \
599     (((af) == AF_INET6) ? ip6addr_ntoa_r((const ip6_addr_t*)(src),(dst),(size)) \
600      : (((af) == AF_INET) ? ip4addr_ntoa_r((const ip4_addr_t*)(src),(dst),(size)) : NULL))
601 #define inet_pton(af,src,dst) \
602     (((af) == AF_INET6) ? ip6addr_aton((src),(ip6_addr_t*)(dst)) \
603      : (((af) == AF_INET) ? ip4addr_aton((src),(ip4_addr_t*)(dst)) : 0))
604 #elif LWIP_IPV4 /* LWIP_IPV4 && LWIP_IPV6 */
605 #define inet_ntop(af,src,dst,size) \
606     (((af) == AF_INET) ? ip4addr_ntoa_r((const ip4_addr_t*)(src),(dst),(size)) : NULL)
607 #define inet_pton(af,src,dst) \
608     (((af) == AF_INET) ? ip4addr_aton((src),(ip4_addr_t*)(dst)) : 0)
609 #else /* LWIP_IPV4 && LWIP_IPV6 */
610 #define inet_ntop(af,src,dst,size) \
611     (((af) == AF_INET6) ? ip6addr_ntoa_r((const ip6_addr_t*)(src),(dst),(size)) : NULL)
612 #define inet_pton(af,src,dst) \
613     (((af) == AF_INET6) ? ip6addr_aton((src),(ip6_addr_t*)(dst)) : 0)
614 #endif /* LWIP_IPV4 && LWIP_IPV6 */
615
616 #endif /* LWIP_COMPAT_SOCKETS */
617
618 #ifdef __cplusplus
619 }
620 #endif
621
622 #endif /* LWIP_SOCKET */
623
624 #endif /* LWIP_HDR_SOCKETS_H */