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