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