39 #ifndef LWIP_HDR_SOCKETS_H
40 #define LWIP_HDR_SOCKETS_H
57 #if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED)
58 typedef u8_t sa_family_t;
62 #if !defined(in_port_t) && !defined(IN_PORT_T_DEFINED)
63 typedef u16_t in_port_t;
70 sa_family_t sin_family;
73 #define SIN_ZERO_LEN 8
74 char sin_zero[SIN_ZERO_LEN];
81 sa_family_t sin6_family;
91 sa_family_t sa_family;
95 struct sockaddr_storage {
97 sa_family_t ss_family;
107 #if !defined(socklen_t) && !defined(SOCKLEN_T_DEFINED)
108 typedef u32_t socklen_t;
113 #if !LWIP_TCPIP_CORE_LOCKING
115 #define LWIP_SETGETSOCKOPT_MAXOPTLEN 16
119 struct lwip_setgetsockopt_data {
128 #if LWIP_MPU_COMPATIBLE
129 u8_t optval[LWIP_SETGETSOCKOPT_MAXOPTLEN];
154 socklen_t msg_namelen;
155 struct iovec *msg_iov;
158 socklen_t msg_controllen;
163 #define SOCK_STREAM 1
170 #define SO_REUSEADDR 0x0004
171 #define SO_KEEPALIVE 0x0008
172 #define SO_BROADCAST 0x0020
178 #define SO_DEBUG 0x0001
179 #define SO_ACCEPTCONN 0x0002
180 #define SO_DONTROUTE 0x0010
181 #define SO_USELOOPBACK 0x0040
182 #define SO_LINGER 0x0080
183 #define SO_DONTLINGER ((int)(~SO_LINGER))
184 #define SO_OOBINLINE 0x0100
185 #define SO_REUSEPORT 0x0200
186 #define SO_SNDBUF 0x1001
187 #define SO_RCVBUF 0x1002
188 #define SO_SNDLOWAT 0x1003
189 #define SO_RCVLOWAT 0x1004
190 #define SO_SNDTIMEO 0x1005
191 #define SO_RCVTIMEO 0x1006
192 #define SO_ERROR 0x1007
193 #define SO_TYPE 0x1008
194 #define SO_CONTIMEO 0x1009
195 #define SO_NO_CHECK 0x100a
209 #define SOL_SOCKET 0xfff
217 #define AF_INET6 AF_UNSPEC
219 #define PF_INET AF_INET
220 #define PF_INET6 AF_INET6
221 #define PF_UNSPEC AF_UNSPEC
224 #define IPPROTO_ICMP 1
225 #define IPPROTO_TCP 6
226 #define IPPROTO_UDP 17
228 #define IPPROTO_IPV6 41
229 #define IPPROTO_ICMPV6 58
231 #define IPPROTO_UDPLITE 136
232 #define IPPROTO_RAW 255
235 #define MSG_PEEK 0x01
236 #define MSG_WAITALL 0x02
238 #define MSG_DONTWAIT 0x08
239 #define MSG_MORE 0x10
252 #define TCP_NODELAY 0x01
253 #define TCP_KEEPALIVE 0x02
254 #define TCP_KEEPIDLE 0x03
255 #define TCP_KEEPINTVL 0x04
256 #define TCP_KEEPCNT 0x05
263 #define IPV6_CHECKSUM 7
264 #define IPV6_V6ONLY 27
267 #if LWIP_UDP && LWIP_UDPLITE
271 #define UDPLITE_SEND_CSCOV 0x01
272 #define UDPLITE_RECV_CSCOV 0x02
276 #if LWIP_MULTICAST_TX_OPTIONS
280 #define IP_MULTICAST_TTL 5
281 #define IP_MULTICAST_IF 6
282 #define IP_MULTICAST_LOOP 7
289 #define IP_ADD_MEMBERSHIP 3
290 #define IP_DROP_MEMBERSHIP 4
292 typedef struct ip_mreq {
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
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
353 #if !defined(FIONREAD) || !defined(FIONBIO)
354 #define IOCPARM_MASK 0x7fU
355 #define IOC_VOID 0x20000000UL
356 #define IOC_OUT 0x40000000UL
357 #define IOC_IN 0x80000000UL
358 #define IOC_INOUT (IOC_IN|IOC_OUT)
361 #define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
363 #define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
365 #define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
369 #define FIONREAD _IOR('f', 127, unsigned long)
372 #define FIONBIO _IOW('f', 126, unsigned long)
377 #define SIOCSHIWAT _IOW('s', 0, unsigned long)
378 #define SIOCGHIWAT _IOR('s', 1, unsigned long)
379 #define SIOCSLOWAT _IOW('s', 2, unsigned long)
380 #define SIOCGLOWAT _IOR('s', 3, unsigned long)
381 #define SIOCATMARK _IOR('s', 7, unsigned long)
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)) { \
415 #define FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 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)))
422 typedef struct fd_set
424 unsigned char fd_bits [(FD_SETSIZE+7)/8];
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"
435 #ifndef LWIP_TIMEVAL_PRIVATE
436 #define LWIP_TIMEVAL_PRIVATE 1
439 #if LWIP_TIMEVAL_PRIVATE
446 #define lwip_socket_init()
447 void lwip_socket_thread_init(
void);
448 void lwip_socket_thread_cleanup(
void);
450 #if LWIP_COMPAT_SOCKETS == 2
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
471 #if LWIP_POSIX_SOCKETS_IO_NAMES
472 #define lwip_read read
473 #define lwip_write write
474 #define lwip_writev writev
476 #define lwip_close close
477 #define closesocket(s) close(s)
478 #define lwip_fcntl fcntl
479 #define lwip_ioctl ioctl
483 int lwip_accept(
int s,
struct sockaddr *addr, socklen_t *addrlen);
484 int lwip_bind(
int s,
const struct sockaddr *name, socklen_t namelen);
485 int lwip_shutdown(
int s,
int how);
486 int lwip_getpeername (
int s,
struct sockaddr *name, socklen_t *namelen);
487 int lwip_getsockname (
int s,
struct sockaddr *name, socklen_t *namelen);
488 int lwip_getsockopt (
int s,
int level,
int optname,
void *optval, socklen_t *optlen);
489 int lwip_setsockopt (
int s,
int level,
int optname,
const void *optval, socklen_t optlen);
490 int lwip_close(
int s);
491 int lwip_connect(
int s,
const struct sockaddr *name, socklen_t namelen);
492 int lwip_listen(
int s,
int backlog);
493 int lwip_recv(
int s,
void *
mem,
size_t len,
int flags);
494 int lwip_read(
int s,
void *
mem,
size_t len);
495 int lwip_recvfrom(
int s,
void *
mem,
size_t len,
int flags,
496 struct sockaddr *from, socklen_t *fromlen);
497 int lwip_send(
int s,
const void *dataptr,
size_t size,
int flags);
498 int lwip_sendmsg(
int s,
const struct msghdr *message,
int flags);
499 int lwip_sendto(
int s,
const void *dataptr,
size_t size,
int flags,
500 const struct sockaddr *to, socklen_t tolen);
501 int lwip_socket(
int domain,
int type,
int protocol);
502 int lwip_write(
int s,
const void *dataptr,
size_t size);
503 int lwip_writev(
int s,
const struct iovec *iov,
int iovcnt);
504 int lwip_select(
int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
505 struct timeval *timeout);
506 int lwip_ioctl(
int s,
long cmd,
void *argp);
507 int lwip_fcntl(
int s,
int cmd,
int val);
509 #if LWIP_COMPAT_SOCKETS
510 #if LWIP_COMPAT_SOCKETS != 2
512 #define accept(s,addr,addrlen) lwip_accept(s,addr,addrlen)
514 #define bind(s,name,namelen) lwip_bind(s,name,namelen)
516 #define shutdown(s,how) lwip_shutdown(s,how)
518 #define getpeername(s,name,namelen) lwip_getpeername(s,name,namelen)
520 #define getsockname(s,name,namelen) lwip_getsockname(s,name,namelen)
522 #define setsockopt(s,level,optname,opval,optlen) lwip_setsockopt(s,level,optname,opval,optlen)
524 #define getsockopt(s,level,optname,opval,optlen) lwip_getsockopt(s,level,optname,opval,optlen)
526 #define closesocket(s) lwip_close(s)
528 #define connect(s,name,namelen) lwip_connect(s,name,namelen)
530 #define listen(s,backlog) lwip_listen(s,backlog)
532 #define recv(s,mem,len,flags) lwip_recv(s,mem,len,flags)
534 #define recvfrom(s,mem,len,flags,from,fromlen) lwip_recvfrom(s,mem,len,flags,from,fromlen)
536 #define send(s,dataptr,size,flags) lwip_send(s,dataptr,size,flags)
538 #define sendmsg(s,message,flags) lwip_sendmsg(s,message,flags)
540 #define sendto(s,dataptr,size,flags,to,tolen) lwip_sendto(s,dataptr,size,flags,to,tolen)
542 #define socket(domain,type,protocol) lwip_socket(domain,type,protocol)
544 #define select(maxfdp1,readset,writeset,exceptset,timeout) lwip_select(maxfdp1,readset,writeset,exceptset,timeout)
546 #define ioctlsocket(s,cmd,argp) lwip_ioctl(s,cmd,argp)
548 #if LWIP_POSIX_SOCKETS_IO_NAMES
550 #define read(s,mem,len) lwip_read(s,mem,len)
552 #define write(s,dataptr,len) lwip_write(s,dataptr,len)
554 #define writev(s,iov,iovcnt) lwip_writev(s,iov,iovcnt)
556 #define close(s) lwip_close(s)
558 #define fcntl(s,cmd,val) lwip_fcntl(s,cmd,val)
560 #define ioctl(s,cmd,argp) lwip_ioctl(s,cmd,argp)
564 #if LWIP_IPV4 && LWIP_IPV6
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))
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))
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)
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)