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