39 #ifndef LWIP_HDR_SOCKETS_H
40 #define LWIP_HDR_SOCKETS_H
60 #if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED)
61 typedef u8_t sa_family_t;
65 #if !defined(in_port_t) && !defined(IN_PORT_T_DEFINED)
66 typedef u16_t in_port_t;
73 sa_family_t sin_family;
76 #define SIN_ZERO_LEN 8
77 char sin_zero[SIN_ZERO_LEN];
84 sa_family_t sin6_family;
94 sa_family_t sa_family;
98 struct sockaddr_storage {
100 sa_family_t ss_family;
110 #if !defined(socklen_t) && !defined(SOCKLEN_T_DEFINED)
111 typedef u32_t socklen_t;
115 #define IOV_MAX 0xFFFF
116 #elif IOV_MAX > 0xFFFF
117 #error "IOV_MAX larger than supported by LwIP"
129 socklen_t msg_namelen;
130 struct iovec *msg_iov;
133 socklen_t msg_controllen;
138 #define MSG_TRUNC 0x04
139 #define MSG_CTRUNC 0x08
155 #define ALIGN_H(size) (((size) + sizeof(long) - 1U) & ~(sizeof(long)-1U))
156 #define ALIGN_D(size) ALIGN_H(size)
158 #define CMSG_FIRSTHDR(mhdr) \
159 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
160 (struct cmsghdr *)(mhdr)->msg_control : \
161 (struct cmsghdr *)NULL)
163 #define CMSG_NXTHDR(mhdr, cmsg) \
164 (((cmsg) == NULL) ? CMSG_FIRSTHDR(mhdr) : \
165 (((u8_t *)(cmsg) + ALIGN_H((cmsg)->cmsg_len) \
166 + ALIGN_D(sizeof(struct cmsghdr)) > \
167 (u8_t *)((mhdr)->msg_control) + (mhdr)->msg_controllen) ? \
168 (struct cmsghdr *)NULL : \
169 (struct cmsghdr *)((void*)((u8_t *)(cmsg) + \
170 ALIGN_H((cmsg)->cmsg_len)))))
172 #define CMSG_DATA(cmsg) ((void*)((u8_t *)(cmsg) + \
173 ALIGN_D(sizeof(struct cmsghdr))))
175 #define CMSG_SPACE(length) (ALIGN_D(sizeof(struct cmsghdr)) + \
178 #define CMSG_LEN(length) (ALIGN_D(sizeof(struct cmsghdr)) + \
182 #define IFNAMSIZ NETIF_NAMESIZE
184 char ifr_name[IFNAMSIZ];
188 #define SOCK_STREAM 1
195 #define SO_REUSEADDR 0x0004
196 #define SO_KEEPALIVE 0x0008
197 #define SO_BROADCAST 0x0020
203 #define SO_DEBUG 0x0001
204 #define SO_ACCEPTCONN 0x0002
205 #define SO_DONTROUTE 0x0010
206 #define SO_USELOOPBACK 0x0040
207 #define SO_LINGER 0x0080
208 #define SO_DONTLINGER ((int)(~SO_LINGER))
209 #define SO_OOBINLINE 0x0100
210 #define SO_REUSEPORT 0x0200
211 #define SO_SNDBUF 0x1001
212 #define SO_RCVBUF 0x1002
213 #define SO_SNDLOWAT 0x1003
214 #define SO_RCVLOWAT 0x1004
215 #define SO_SNDTIMEO 0x1005
216 #define SO_RCVTIMEO 0x1006
217 #define SO_ERROR 0x1007
218 #define SO_TYPE 0x1008
219 #define SO_CONTIMEO 0x1009
220 #define SO_NO_CHECK 0x100a
221 #define SO_BINDTODEVICE 0x100b
234 #define SOL_SOCKET 0xfff
242 #define AF_INET6 AF_UNSPEC
244 #define PF_INET AF_INET
245 #define PF_INET6 AF_INET6
246 #define PF_UNSPEC AF_UNSPEC
249 #define IPPROTO_ICMP 1
250 #define IPPROTO_TCP 6
251 #define IPPROTO_UDP 17
253 #define IPPROTO_IPV6 41
254 #define IPPROTO_ICMPV6 58
256 #define IPPROTO_UDPLITE 136
257 #define IPPROTO_RAW 255
260 #define MSG_PEEK 0x01
261 #define MSG_WAITALL 0x02
263 #define MSG_DONTWAIT 0x08
264 #define MSG_MORE 0x10
265 #define MSG_NOSIGNAL 0x20
279 #define TCP_NODELAY 0x01
280 #define TCP_KEEPALIVE 0x02
281 #define TCP_KEEPIDLE 0x03
282 #define TCP_KEEPINTVL 0x04
283 #define TCP_KEEPCNT 0x05
290 #define IPV6_CHECKSUM 7
291 #define IPV6_V6ONLY 27
294 #if LWIP_UDP && LWIP_UDPLITE
298 #define UDPLITE_SEND_CSCOV 0x01
299 #define UDPLITE_RECV_CSCOV 0x02
303 #if LWIP_MULTICAST_TX_OPTIONS
307 #define IP_MULTICAST_TTL 5
308 #define IP_MULTICAST_IF 6
309 #define IP_MULTICAST_LOOP 7
316 #define IP_ADD_MEMBERSHIP 3
317 #define IP_DROP_MEMBERSHIP 4
319 typedef struct ip_mreq {
327 unsigned int ipi_ifindex;
336 #define IPV6_JOIN_GROUP 12
337 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
338 #define IPV6_LEAVE_GROUP 13
339 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
341 typedef struct ipv6_mreq {
343 unsigned int ipv6mr_interface;
363 #define IPTOS_TOS_MASK 0x1E
364 #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
365 #define IPTOS_LOWDELAY 0x10
366 #define IPTOS_THROUGHPUT 0x08
367 #define IPTOS_RELIABILITY 0x04
368 #define IPTOS_LOWCOST 0x02
369 #define IPTOS_MINCOST IPTOS_LOWCOST
380 #define IPTOS_PREC_MASK 0xe0
381 #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
382 #define IPTOS_PREC_NETCONTROL 0xe0
383 #define IPTOS_PREC_INTERNETCONTROL 0xc0
384 #define IPTOS_PREC_CRITIC_ECP 0xa0
385 #define IPTOS_PREC_FLASHOVERRIDE 0x80
386 #define IPTOS_PREC_FLASH 0x60
387 #define IPTOS_PREC_IMMEDIATE 0x40
388 #define IPTOS_PREC_PRIORITY 0x20
389 #define IPTOS_PREC_ROUTINE 0x00
402 #if !defined(FIONREAD) || !defined(FIONBIO)
403 #define IOCPARM_MASK 0x7fU
404 #define IOC_VOID 0x20000000UL
405 #define IOC_OUT 0x40000000UL
406 #define IOC_IN 0x80000000UL
407 #define IOC_INOUT (IOC_IN|IOC_OUT)
410 #define _IO(x,y) ((long)(IOC_VOID|((x)<<8)|(y)))
412 #define _IOR(x,y,t) ((long)(IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)))
414 #define _IOW(x,y,t) ((long)(IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)))
418 #define FIONREAD _IOR('f', 127, unsigned long)
421 #define FIONBIO _IOW('f', 126, unsigned long)
426 #define SIOCSHIWAT _IOW('s', 0, unsigned long)
427 #define SIOCGHIWAT _IOR('s', 1, unsigned long)
428 #define SIOCSLOWAT _IOW('s', 2, unsigned long)
429 #define SIOCGLOWAT _IOR('s', 3, unsigned long)
430 #define SIOCATMARK _IOR('s', 7, unsigned long)
447 #define O_NDELAY O_NONBLOCK
456 #define O_RDWR (O_RDONLY|O_WRONLY)
469 #define FD_SETSIZE MEMP_NUM_NETCONN
470 #define LWIP_SELECT_MAXNFDS (FD_SETSIZE + LWIP_SOCKET_OFFSET)
471 #define FDSETSAFESET(n, code) do { \
472 if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \
474 #define FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\
476 #define FD_SET(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] = (u8_t)((p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] | (1 << (((n)-LWIP_SOCKET_OFFSET) & 7))))
477 #define FD_CLR(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] = (u8_t)((p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7))))
478 #define FD_ISSET(n,p) FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
479 #define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
481 typedef struct fd_set
483 unsigned char fd_bits [(FD_SETSIZE+7)/8];
486 #elif FD_SETSIZE < (LWIP_SOCKET_OFFSET + MEMP_NUM_NETCONN)
487 #error "external FD_SETSIZE too small for number of sockets"
489 #define LWIP_SELECT_MAXNFDS FD_SETSIZE
494 #if !defined(POLLIN) && !defined(POLLOUT)
500 #define POLLRDNORM 0x10
501 #define POLLRDBAND 0x20
503 #define POLLWRNORM 0x80
504 #define POLLWRBAND 0x100
505 #define POLLHUP 0x200
506 typedef unsigned int nfds_t;
517 #ifndef LWIP_TIMEVAL_PRIVATE
518 #define LWIP_TIMEVAL_PRIVATE 1
521 #if LWIP_TIMEVAL_PRIVATE
528 #define lwip_socket_init()
529 void lwip_socket_thread_init(
void);
530 void lwip_socket_thread_cleanup(
void);
532 #if LWIP_COMPAT_SOCKETS == 2
534 #define lwip_accept accept
535 #define lwip_bind bind
536 #define lwip_shutdown shutdown
537 #define lwip_getpeername getpeername
538 #define lwip_getsockname getsockname
539 #define lwip_setsockopt setsockopt
540 #define lwip_getsockopt getsockopt
541 #define lwip_close closesocket
542 #define lwip_connect connect
543 #define lwip_listen listen
544 #define lwip_recv recv
545 #define lwip_recvmsg recvmsg
546 #define lwip_recvfrom recvfrom
547 #define lwip_send send
548 #define lwip_sendmsg sendmsg
549 #define lwip_sendto sendto
550 #define lwip_socket socket
551 #if LWIP_SOCKET_SELECT
552 #define lwip_select select
555 #define lwip_poll poll
557 #define lwip_ioctl ioctlsocket
558 #define lwip_inet_ntop inet_ntop
559 #define lwip_inet_pton inet_pton
561 #if LWIP_POSIX_SOCKETS_IO_NAMES
562 #define lwip_read read
563 #define lwip_readv readv
564 #define lwip_write write
565 #define lwip_writev writev
567 #define lwip_close close
568 #define closesocket(s) close(s)
569 int fcntl(
int s,
int cmd, ...);
571 #define lwip_ioctl ioctl
572 #define ioctlsocket ioctl
576 int lwip_accept(
int s,
struct sockaddr *addr, socklen_t *addrlen);
577 int lwip_bind(
int s,
const struct sockaddr *name, socklen_t namelen);
578 int lwip_shutdown(
int s,
int how);
579 int lwip_getpeername (
int s,
struct sockaddr *name, socklen_t *namelen);
580 int lwip_getsockname (
int s,
struct sockaddr *name, socklen_t *namelen);
581 int lwip_getsockopt (
int s,
int level,
int optname,
void *optval, socklen_t *optlen);
582 int lwip_setsockopt (
int s,
int level,
int optname,
const void *optval, socklen_t optlen);
583 int lwip_close(
int s);
584 int lwip_connect(
int s,
const struct sockaddr *name, socklen_t namelen);
585 int lwip_listen(
int s,
int backlog);
586 ssize_t lwip_recv(
int s,
void *
mem,
size_t len,
int flags);
587 ssize_t lwip_read(
int s,
void *
mem,
size_t len);
588 ssize_t lwip_readv(
int s,
const struct iovec *iov,
int iovcnt);
589 ssize_t lwip_recvfrom(
int s,
void *
mem,
size_t len,
int flags,
590 struct sockaddr *from, socklen_t *fromlen);
591 ssize_t lwip_recvmsg(
int s,
struct msghdr *message,
int flags);
592 ssize_t lwip_send(
int s,
const void *dataptr,
size_t size,
int flags);
593 ssize_t lwip_sendmsg(
int s,
const struct msghdr *message,
int flags);
594 ssize_t lwip_sendto(
int s,
const void *dataptr,
size_t size,
int flags,
595 const struct sockaddr *to, socklen_t tolen);
596 int lwip_socket(
int domain,
int type,
int protocol);
597 ssize_t lwip_write(
int s,
const void *dataptr,
size_t size);
598 ssize_t lwip_writev(
int s,
const struct iovec *iov,
int iovcnt);
599 #if LWIP_SOCKET_SELECT
600 int lwip_select(
int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
601 struct timeval *timeout);
604 int lwip_poll(
struct pollfd *fds, nfds_t nfds,
int timeout);
606 int lwip_ioctl(
int s,
long cmd,
void *argp);
607 int lwip_fcntl(
int s,
int cmd,
int val);
608 const char *lwip_inet_ntop(
int af,
const void *src,
char *dst, socklen_t size);
609 int lwip_inet_pton(
int af,
const char *src,
void *dst);
611 #if LWIP_COMPAT_SOCKETS
612 #if LWIP_COMPAT_SOCKETS != 2
614 #define accept(s,addr,addrlen) lwip_accept(s,addr,addrlen)
616 #define bind(s,name,namelen) lwip_bind(s,name,namelen)
618 #define shutdown(s,how) lwip_shutdown(s,how)
620 #define getpeername(s,name,namelen) lwip_getpeername(s,name,namelen)
622 #define getsockname(s,name,namelen) lwip_getsockname(s,name,namelen)
624 #define setsockopt(s,level,optname,opval,optlen) lwip_setsockopt(s,level,optname,opval,optlen)
626 #define getsockopt(s,level,optname,opval,optlen) lwip_getsockopt(s,level,optname,opval,optlen)
628 #define closesocket(s) lwip_close(s)
630 #define connect(s,name,namelen) lwip_connect(s,name,namelen)
632 #define listen(s,backlog) lwip_listen(s,backlog)
634 #define recv(s,mem,len,flags) lwip_recv(s,mem,len,flags)
636 #define recvmsg(s,message,flags) lwip_recvmsg(s,message,flags)
638 #define recvfrom(s,mem,len,flags,from,fromlen) lwip_recvfrom(s,mem,len,flags,from,fromlen)
640 #define send(s,dataptr,size,flags) lwip_send(s,dataptr,size,flags)
642 #define sendmsg(s,message,flags) lwip_sendmsg(s,message,flags)
644 #define sendto(s,dataptr,size,flags,to,tolen) lwip_sendto(s,dataptr,size,flags,to,tolen)
646 #define socket(domain,type,protocol) lwip_socket(domain,type,protocol)
647 #if LWIP_SOCKET_SELECT
649 #define select(maxfdp1,readset,writeset,exceptset,timeout) lwip_select(maxfdp1,readset,writeset,exceptset,timeout)
653 #define poll(fds,nfds,timeout) lwip_poll(fds,nfds,timeout)
656 #define ioctlsocket(s,cmd,argp) lwip_ioctl(s,cmd,argp)
658 #define inet_ntop(af,src,dst,size) lwip_inet_ntop(af,src,dst,size)
660 #define inet_pton(af,src,dst) lwip_inet_pton(af,src,dst)
662 #if LWIP_POSIX_SOCKETS_IO_NAMES
664 #define read(s,mem,len) lwip_read(s,mem,len)
666 #define readv(s,iov,iovcnt) lwip_readv(s,iov,iovcnt)
668 #define write(s,dataptr,len) lwip_write(s,dataptr,len)
670 #define writev(s,iov,iovcnt) lwip_writev(s,iov,iovcnt)
672 #define close(s) lwip_close(s)
674 #define fcntl(s,cmd,val) lwip_fcntl(s,cmd,val)
676 #define ioctl(s,cmd,argp) lwip_ioctl(s,cmd,argp)
uint32_t u32_t
Definition: arch.h:129
uint8_t u8_t
Definition: arch.h:125
uint16_t u16_t
Definition: arch.h:127
int ssize_t
Definition: arch.h:202