1 /* 2 * Copyright (C) 2023 Joan Lled� <jlledom@member.fsf.org> 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 * and/or other materials provided with the distribution. 12 * 3. The name of the author may not be used to endorse or promote products 13 * derived from this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 16 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 18 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 20 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 23 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 24 * OF SUCH DAMAGE. 25 */ 26 27 #ifndef HURD_LWIP_POSIX_SOCKET_H 28 #define HURD_LWIP_POSIX_SOCKET_H 29 30 #include <sys/socket.h> 31 #include <poll.h> 32 #include <errno.h> 33 #include LWIP_SOCKET_EXTERNAL_HEADER_INET_H 34 typedef size_t msg_iovlen_t; 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 #ifdef _HAVE_SA_LEN 41 #define HAVE_SA_LEN _HAVE_SA_LEN 42 #else 43 #define HAVE_SA_LEN 0 44 #endif /* _HAVE_SA_LEN */ 45 46 /* Address length safe read and write */ 47 #if HAVE_SA_LEN 48 #define IP4ADDR_SOCKADDR_SET_LEN(sin) \ 49 (sin)->sin_len = sizeof(struct sockaddr_in) 50 #define IP6ADDR_SOCKADDR_SET_LEN(sin6) \ 51 (sin6)->sin6_len = sizeof(struct sockaddr_in6) 52 #define IPADDR_SOCKADDR_GET_LEN(addr) \ 53 (addr)->sa.sa_len 54 #else 55 #define IP4ADDR_SOCKADDR_SET_LEN(addr) 56 #define IP6ADDR_SOCKADDR_SET_LEN(addr) 57 #define IPADDR_SOCKADDR_GET_LEN(addr) \ 58 ((addr)->sa.sa_family == AF_INET ? sizeof(struct sockaddr_in) \ 59 : ((addr)->sa.sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : 0)) 60 #endif /* HAVE_SA_LEN */ 61 62 #define SIN_ZERO_LEN sizeof (struct sockaddr) - \ 63 __SOCKADDR_COMMON_SIZE - \ 64 sizeof (in_port_t) - \ 65 sizeof (struct in_addr) 66 67 #if !defined IOV_MAX 68 #define IOV_MAX 0xFFFF 69 #elif IOV_MAX > 0xFFFF 70 #error "IOV_MAX larger than supported by LwIP" 71 #endif /* IOV_MAX */ 72 73 #define LWIP_SELECT_MAXNFDS (FD_SETSIZE + LWIP_SOCKET_OFFSET) 74 75 #if LWIP_UDP && LWIP_UDPLITE 76 /* 77 * Options for level IPPROTO_UDPLITE 78 */ 79 #define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */ 80 #define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */ 81 #endif /* LWIP_UDP && LWIP_UDPLITE*/ 82 83 #if 0 84 void lwip_socket_thread_init(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: initialize thread-local semaphore */ 85 void lwip_socket_thread_cleanup(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: destroy thread-local semaphore */ 86 87 int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); 88 int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen); 89 int lwip_shutdown(int s, int how); 90 int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen); 91 int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen); 92 int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen); 93 int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen); 94 int lwip_close(int s); 95 int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen); 96 int lwip_listen(int s, int backlog); 97 ssize_t lwip_recv(int s, void *mem, size_t len, int flags); 98 ssize_t lwip_read(int s, void *mem, size_t len); 99 ssize_t lwip_readv(int s, const struct iovec *iov, int iovcnt); 100 ssize_t lwip_recvfrom(int s, void *mem, size_t len, int flags, 101 struct sockaddr *from, socklen_t *fromlen); 102 ssize_t lwip_recvmsg(int s, struct msghdr *message, int flags); 103 ssize_t lwip_send(int s, const void *dataptr, size_t size, int flags); 104 ssize_t lwip_sendmsg(int s, const struct msghdr *message, int flags); 105 ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags, 106 const struct sockaddr *to, socklen_t tolen); 107 int lwip_socket(int domain, int type, int protocol); 108 ssize_t lwip_write(int s, const void *dataptr, size_t size); 109 ssize_t lwip_writev(int s, const struct iovec *iov, int iovcnt); 110 #if LWIP_SOCKET_SELECT 111 int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, 112 struct timeval *timeout); 113 #endif 114 #if LWIP_SOCKET_POLL 115 int lwip_poll(struct pollfd *fds, nfds_t nfds, int timeout); 116 #endif 117 int lwip_ioctl(int s, long cmd, void *argp); 118 int lwip_fcntl(int s, int cmd, int val); 119 const char *lwip_inet_ntop(int af, const void *src, char *dst, socklen_t size); 120 int lwip_inet_pton(int af, const char *src, void *dst); 121 #endif 122 123 /* Unsupported identifiers */ 124 #ifndef SO_NO_CHECK 125 #define SO_NO_CHECK 0xFF 126 #endif 127 #ifndef SO_BINDTODEVICE 128 #define SO_BINDTODEVICE 0xFE 129 #endif 130 #ifndef MSG_MORE 131 #define MSG_MORE 0x0 132 #endif 133 #ifndef TCP_KEEPALIVE 134 #define TCP_KEEPALIVE 0xFF 135 #endif 136 #ifndef TCP_KEEPIDLE 137 #define TCP_KEEPIDLE 0xFE 138 #endif 139 #ifndef TCP_KEEPINTVL 140 #define TCP_KEEPINTVL 0xFD 141 #endif 142 #ifndef TCP_KEEPCNT 143 #define TCP_KEEPCNT 0xFC 144 #endif 145 146 #ifdef __cplusplus 147 } 148 #endif 149 150 #endif /* HURD_LWIP_POSIX_SOCKET_H */ 151