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