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 #include "lwip/sys.h" 46 #include "lwip/ip_addr.h" 47 #include "lwip/netif.h" 48 #include "lwip/err.h" 49 #include "lwip/inet.h" 50 #include "lwip/errno.h" 51 #if LWIP_LITEOS_COMPAT 52 #if LWIP_EXT_POLL_SUPPORT 53 #include "fs/fs.h" 54 #include "poll.h" 55 #endif /* LWIP_EXT_POLL_SUPPORT */ 56 #endif /* LWIP_LITEOS_COMPAT */ 57 #include <string.h> 58 59 #if LWIP_FREERTOS_COMPAT 60 #include "sys/select.h" 61 #include "sys/socket.h" 62 #include "poll.h" 63 #endif /* LWIP_FREERTOS_COMPAT */ 64 65 #ifdef __cplusplus 66 extern "C" { 67 #endif 68 69 #if LWIP_IPV4 70 #ifndef SIN_ZERO_LEN 71 #define SIN_ZERO_LEN 8 72 #endif 73 #endif 74 75 #ifdef LWIP_LITEOS_A_COMPAT 76 #if LWIP_IPV6 77 struct in6_ifreq { 78 struct in6_addr ifr6_addr; 79 u32_t ifr6_prefixlen; 80 s32_t ifr6_ifindex; 81 }; 82 #endif /* LWIP_IPV6 */ 83 84 #else /* LWIP_LITEOS_A_COMPAT */ 85 #ifndef TCP_INDICATORS_DEFINED 86 #if LWIP_TCP 87 /* 88 * @brief Indicates socket repair options. 89 */ 90 enum { 91 TCP_NO_QUEUE, /* Indicates no queue. */ 92 TCP_RECV_QUEUE, /* Indicates the receive queue. */ 93 TCP_SEND_QUEUE, /* Indicates the send queue. */ 94 TCP_QUEUES_NR, /* Indicates Queue NR. */ 95 }; 96 #endif /* LWIP_TCP */ 97 #endif /* TCP_INDICATORS_DEFINED */ 98 #endif /* LWIP_LITEOS_A_COMPAT */ 99 100 #if !LWIP_LITEOS_COMPAT && !LWIP_FREERTOS_COMPAT 101 102 /* If your port already typedef's sa_family_t, define SA_FAMILY_T_DEFINED 103 to prevent this code from redefining it. */ 104 #if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED) 105 typedef u16_t sa_family_t; 106 #endif 107 /* If your port already typedef's in_port_t, define IN_PORT_T_DEFINED 108 to prevent this code from redefining it. */ 109 #if !defined(in_port_t) && !defined(IN_PORT_T_DEFINED) 110 typedef u16_t in_port_t; 111 #endif 112 113 #if LWIP_IPV4 114 /* members are in network byte order */ 115 struct sockaddr_in { 116 u8_t sin_len; 117 sa_family_t sin_family; 118 in_port_t sin_port; 119 struct in_addr sin_addr; 120 char sin_zero[SIN_ZERO_LEN]; 121 }; 122 #endif /* LWIP_IPV4 */ 123 124 #if LWIP_IPV6 125 /* @brief Defines the socket address. */ 126 /** 127 @page RFC-2553_RFC-3493 RFC-2553/3493 128 @par Compliant Sections 129 Section 3.4 Socket Address Structure for 4.4 BSD-Based Systems 130 @par Behavior Description 131 Systems that provide this version of the sockaddr_in6 data structure must also declare SIN6_LEN 132 as a result of including the <netinet/in.h> header. This macro allows applications to determine 133 whether they are being built on a system that supports the 4.3BSD or 4.4BSD variants of the data structure. \n 134 Behavior: Macro SIN6_LEN for applications to determine which version of sockaddr_in6 stack supports.\n 135 If SIN6_LEN is defined the version of sockaddr_in6 is 4.4 BSD compliant. 136 */ 137 /* RFC 2553/3493 138 Systems that provide this version of the sockaddr_in6(4.4 BSD) data structure must also 139 declare SIN6_LEN . This macro allows applications to determine whether they are being built 140 on a system that supports the 4.3BSD or 4.4BSD variants of the data structure. */ 141 #define SIN6_LEN 142 struct sockaddr_in6 { 143 u8_t sin6_len; /* < Specifies the length of the structure. */ 144 sa_family_t sin6_family; /* AF_INET6 */ 145 in_port_t sin6_port; /* Transport layer port # */ 146 u32_t sin6_flowinfo; /* IPv6 flow information */ 147 struct in6_addr sin6_addr; /* IPv6 address */ 148 u32_t sin6_scope_id; /* Set of interfaces for scope */ 149 }; 150 #endif /* LWIP_IPV6 */ 151 152 struct sockaddr { 153 u8_t sa_len; 154 sa_family_t sa_family; 155 char sa_data[14]; 156 }; 157 158 #if PF_PKT_SUPPORT 159 #define MAX_HWADDR_LEN 8U 160 161 /** 162 * @note 163 * You must enable PF_PKT_SUPPORT to use the sockaddr_ll data structure. \n 164 */ 165 struct sockaddr_ll { 166 u16_t sll_family; /**< Specifies the socket family. Always AF_PACKET */ 167 u16_t sll_protocol; /**< Specifies the Ethernet protocol. Physical layer protocol. */ 168 int sll_ifindex; /**< Specifies the network interface index. Starts from 1. */ 169 u16_t sll_hatype; /**< Specifies the hat type. */ 170 u8_t sll_pkttype; /**< Specifies the packet type. */ 171 u8_t sll_halen; /**< Specifies the physical layer address length. */ 172 u8_t sll_addr[MAX_HWADDR_LEN]; /**< Specifies the physical layer address. */ 173 }; 174 #endif /* PF_PKT_SUPPORT */ 175 176 struct sockaddr_storage { 177 u8_t s2_len; 178 sa_family_t ss_family; 179 char s2_data1[2]; 180 u32_t s2_data2[3]; 181 #if LWIP_IPV6 182 u32_t s2_data3[3]; 183 #endif /* LWIP_IPV6 */ 184 }; 185 186 /* If your port already typedef's socklen_t, define SOCKLEN_T_DEFINED 187 to prevent this code from redefining it. */ 188 #if !defined(socklen_t) && !defined(SOCKLEN_T_DEFINED) 189 typedef u32_t socklen_t; 190 #endif 191 192 #if !defined(iovec) 193 struct iovec { 194 void *iov_base; 195 size_t iov_len; 196 }; 197 #endif 198 199 struct msghdr { 200 void *msg_name; 201 socklen_t msg_namelen; 202 struct iovec *msg_iov; 203 int msg_iovlen; 204 void *msg_control; 205 socklen_t msg_controllen; 206 int msg_flags; 207 }; 208 209 /* struct msghdr->msg_flags bit field values */ 210 #define MSG_TRUNC 0x04 211 #define MSG_CTRUNC 0x08 212 213 /* RFC 3542, Section 20: Ancillary Data */ 214 struct cmsghdr { 215 socklen_t cmsg_len; /* number of bytes, including header */ 216 int cmsg_level; /* originating protocol */ 217 int cmsg_type; /* protocol-specific type */ 218 }; 219 /* Data section follows header and possible padding, typically referred to as 220 unsigned char cmsg_data[]; */ 221 222 /* cmsg header/data alignment. NOTE: we align to native word size (double word 223 size on 16-bit arch) so structures are not placed at an unaligned address. 224 16-bit arch needs double word to ensure 32-bit alignment because socklen_t 225 could be 32 bits. If we ever have cmsg data with a 64-bit variable, alignment 226 will need to increase long long */ 227 #define ALIGN_H(size) (((size) + sizeof(long) - 1U) & ~(sizeof(long)-1U)) 228 #define ALIGN_D(size) ALIGN_H(size) 229 230 #define CMSG_FIRSTHDR(mhdr) \ 231 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ 232 (struct cmsghdr *)(mhdr)->msg_control : \ 233 (struct cmsghdr *)NULL) 234 235 #define CMSG_NXTHDR(mhdr, cmsg) \ 236 (((cmsg) == NULL) ? CMSG_FIRSTHDR(mhdr) : \ 237 (((u8_t *)(cmsg) + ALIGN_H((cmsg)->cmsg_len) \ 238 + ALIGN_D(sizeof(struct cmsghdr)) > \ 239 (u8_t *)((mhdr)->msg_control) + (mhdr)->msg_controllen) ? \ 240 (struct cmsghdr *)NULL : \ 241 (struct cmsghdr *)((void*)((u8_t *)(cmsg) + \ 242 ALIGN_H((cmsg)->cmsg_len))))) 243 244 #define CMSG_DATA(cmsg) ((void*)((u8_t *)(cmsg) + \ 245 ALIGN_D(sizeof(struct cmsghdr)))) 246 247 #define CMSG_SPACE(length) (ALIGN_D(sizeof(struct cmsghdr)) + \ 248 ALIGN_H(length)) 249 250 #define CMSG_LEN(length) (ALIGN_D(sizeof(struct cmsghdr)) + \ 251 length) 252 253 /* Socket protocol types (TCP/UDP/RAW) */ 254 #define SOCK_STREAM 1 255 #define SOCK_DGRAM 2 256 #define SOCK_RAW 3 257 258 #define SOCK_TYPE_MASK 0xf 259 260 /* 261 * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c) 262 */ 263 #define SO_REUSEADDR 0x0004 /* Allow local address reuse */ 264 #define SO_KEEPALIVE 0x0008 /* keep connections alive */ 265 #define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */ 266 267 268 /* 269 * Additional options, not kept in so_options. 270 */ 271 #define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */ 272 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ 273 #define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */ 274 #define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */ 275 #define SO_LINGER 0x0080 /* linger on close if data present */ 276 #define SO_DONTLINGER ((int)(~SO_LINGER)) 277 #define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */ 278 #define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */ 279 #define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */ 280 #define SO_RCVBUF 0x1002 /* receive buffer size */ 281 #define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */ 282 #define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */ 283 #define SO_SNDTIMEO 0x1005 /* send timeout */ 284 #define SO_RCVTIMEO 0x1006 /* receive timeout */ 285 #define SO_ERROR 0x1007 /* get error status and clear */ 286 #define SO_TYPE 0x1008 /* get socket type */ 287 #define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */ 288 #define SO_NO_CHECK 0x100a /* don't create UDP checksum */ 289 #define SO_BINDTODEVICE 0x100b /* bind to device */ 290 #define SO_ATTACH_FILTER 0x100c /* attach a filter to a PF packet socket */ 291 #define SO_DETACH_FILTER 0x100d /* detach a filter to a PF packet socket */ 292 #define SO_PRIORITY 0x100e 293 294 /* 295 * Structure used for manipulating linger option. 296 */ 297 struct linger { 298 int l_onoff; /* option on/off */ 299 int l_linger; /* linger time in seconds */ 300 }; 301 302 /* 303 * Level number for (get/set)sockopt() to apply to socket itself. 304 */ 305 #define SOL_SOCKET 1 /* options for socket level */ 306 307 308 #define AF_UNSPEC 0 309 #define AF_INET 2 310 #if LWIP_IPV6 311 #define AF_INET6 10 312 #else /* LWIP_IPV6 */ 313 #define AF_INET6 AF_UNSPEC 314 #endif /* LWIP_IPV6 */ 315 #define PF_INET AF_INET 316 #define PF_INET6 AF_INET6 317 #define PF_UNSPEC AF_UNSPEC 318 319 #if PF_PKT_SUPPORT 320 /** Packet family. */ 321 #define PF_PACKET 17 322 /** Pakcet family socket level */ 323 #define SOL_PACKET 263 324 #endif 325 326 #define IPPROTO_IP 0 327 #define IPPROTO_ICMP 1 328 #define IPPROTO_TCP 6 329 #define IPPROTO_UDP 17 330 #if LWIP_IPV6 331 #define IPPROTO_IPV6 41 332 #define IPPROTO_ICMPV6 58 333 #endif /* LWIP_IPV6 */ 334 #define IPPROTO_UDPLITE 136 335 #define IPPROTO_RAW 255 336 337 /* Flags we can use with send and recv. */ 338 #define MSG_PEEK 0x01 /* Peeks at an incoming message */ 339 #define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */ 340 #define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */ 341 #define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */ 342 #define MSG_MORE 0x10 /* Sender will send more */ 343 #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. */ 344 345 346 /* 347 * Options for level IPPROTO_IP 348 */ 349 #define IP_TOS 1 350 #define IP_TTL 2 351 #define IP_PKTINFO 8 352 #define IP_HDRINCL 9 353 354 #if LWIP_TCP 355 /* 356 * Options for level IPPROTO_TCP 357 */ 358 #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ 359 #define TCP_MAXSEG 0x02 /* Limit MSS */ 360 #define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */ 361 #define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */ 362 #define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */ 363 #define TCP_QUEUE_SEQ 0x15 /* set sequence number of repaired queue. */ 364 365 /* 366 * User-gettable options (used with getsockopt). 367 */ 368 #ifndef TCP_INFO 369 /** Information about this connection. */ 370 #define TCP_INFO 11 371 #endif 372 #endif /* LWIP_TCP */ 373 374 #if LWIP_IPV6 375 /* 376 * Options for level IPPROTO_IPV6 377 */ 378 #define IPV6_CHECKSUM 7 /* RFC3542: calculate and insert the ICMPv6 checksum for raw sockets. */ 379 #define IPV6_V6ONLY 26 /* RFC3493: boolean control to restrict AF_INET6 sockets to IPv6 communications only. */ 380 #define IPV6_UNICAST_HOPS 16 /* RFC 2553/3493 : to get the unicast hop limit for outgoing unicast packets */ 381 382 #if LWIP_MULTICAST_TX_OPTIONS 383 #define IPV6_MULTICAST_IF 17 384 #define IPV6_MULTICAST_HOPS 18 385 #define IPV6_MULTICAST_LOOP 19 386 #endif /* LWIP_MULTICAST_TX_OPTIONS */ 387 #define IPV6_RECVPKTINFO 49 388 #endif /* LWIP_IPV6 */ 389 390 #if LWIP_UDP && LWIP_UDPLITE 391 /* 392 * Options for level IPPROTO_UDPLITE 393 */ 394 #define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */ 395 #define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */ 396 #endif /* LWIP_UDP && LWIP_UDPLITE*/ 397 398 399 #if LWIP_MULTICAST_TX_OPTIONS 400 /* 401 * Options and types for UDP multicast traffic handling 402 */ 403 #define IP_MULTICAST_TTL 5 404 #define IP_MULTICAST_IF 6 405 #define IP_MULTICAST_LOOP 7 406 #endif /* LWIP_MULTICAST_TX_OPTIONS */ 407 408 #if LWIP_IGMP 409 /* 410 * Options and types related to multicast membership 411 */ 412 #define IP_ADD_MEMBERSHIP 3 413 #define IP_DROP_MEMBERSHIP 4 414 415 typedef struct ip_mreq { 416 struct in_addr imr_multiaddr; /* IP multicast address of group */ 417 struct in_addr imr_interface; /* local IP address of interface */ 418 } ip_mreq; 419 #endif /* LWIP_IGMP */ 420 421 #if LWIP_IPV4 422 struct in_pktinfo { 423 unsigned int ipi_ifindex; /* Interface index */ 424 struct in_addr ipi_addr; /* Destination (from header) address */ 425 }; 426 #endif /* LWIP_IPV4 */ 427 428 #if LWIP_IPV6_MLD 429 /* 430 * Options and types related to IPv6 multicast membership 431 */ 432 #define IPV6_JOIN_GROUP 12 433 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP 434 #define IPV6_LEAVE_GROUP 13 435 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP 436 437 typedef struct ipv6_mreq { 438 struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast addr */ 439 unsigned int ipv6mr_interface; /* interface index, or 0 */ 440 } ipv6_mreq; 441 #endif /* LWIP_IPV6_MLD */ 442 443 #if LWIP_IPV6 444 struct in6_ifreq { 445 struct in6_addr ifr6_addr; 446 u32_t ifr6_prefixlen; 447 s32_t ifr6_ifindex; 448 }; 449 #endif /* LWIP_IPV6 */ 450 451 /* 452 * The Type of Service provides an indication of the abstract 453 * parameters of the quality of service desired. These parameters are 454 * to be used to guide the selection of the actual service parameters 455 * when transmitting a datagram through a particular network. Several 456 * networks offer service precedence, which somehow treats high 457 * precedence traffic as more important than other traffic (generally 458 * by accepting only traffic above a certain precedence at time of high 459 * load). The major choice is a three way tradeoff between low-delay, 460 * high-reliability, and high-throughput. 461 * The use of the Delay, Throughput, and Reliability indications may 462 * increase the cost (in some sense) of the service. In many networks 463 * better performance for one of these parameters is coupled with worse 464 * performance on another. Except for very unusual cases at most two 465 * of these three indications should be set. 466 */ 467 #define IPTOS_TOS_MASK 0x1E 468 #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) 469 #define IPTOS_LOWDELAY 0x10 470 #define IPTOS_THROUGHPUT 0x08 471 #define IPTOS_RELIABILITY 0x04 472 #define IPTOS_LOWCOST 0x02 473 #define IPTOS_MINCOST IPTOS_LOWCOST 474 475 /* 476 * The Network Control precedence designation is intended to be used 477 * within a network only. The actual use and control of that 478 * designation is up to each network. The Internetwork Control 479 * designation is intended for use by gateway control originators only. 480 * If the actual use of these precedence designations is of concern to 481 * a particular network, it is the responsibility of that network to 482 * control the access to, and use of, those precedence designations. 483 */ 484 #define IPTOS_PREC_MASK 0xe0 485 #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) 486 #define IPTOS_PREC_NETCONTROL 0xe0 487 #define IPTOS_PREC_INTERNETCONTROL 0xc0 488 #define IPTOS_PREC_CRITIC_ECP 0xa0 489 #define IPTOS_PREC_FLASHOVERRIDE 0x80 490 #define IPTOS_PREC_FLASH 0x60 491 #define IPTOS_PREC_IMMEDIATE 0x40 492 #define IPTOS_PREC_PRIORITY 0x20 493 #define IPTOS_PREC_ROUTINE 0x00 494 495 496 /* 497 * Commands for ioctlsocket(), taken from the BSD file fcntl.h. 498 * lwip_ioctl only supports FIONREAD and FIONBIO, for now 499 * 500 * Ioctl's have the command encoded in the lower word, 501 * and the size of any in or out parameters in the upper 502 * word. The high 2 bits of the upper word are used 503 * to encode the in/out status of the parameter; for now 504 * we restrict parameters to at most 128 bytes. 505 */ 506 #if !defined(FIONREAD) || !defined(FIONBIO) 507 #define IOCPARM_MASK 0x7fUL /* parameters must be < 128 bytes */ 508 #define IOC_VOID 0x20000000UL /* no parameters */ 509 #define IOC_OUT 0x40000000UL /* copy out parameters */ 510 #define IOC_IN 0x80000000UL /* copy in parameters */ 511 #define IOC_INOUT (IOC_IN|IOC_OUT) 512 /* 0x20000000 distinguishes new & 513 old ioctl's */ 514 #define _IO(x,y) ((long)(IOC_VOID|((x)<<8)|(y))) 515 516 #define _IOR(x,y,t) ((long)(IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))) 517 518 #define _IOW(x,y,t) ((long)(IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))) 519 520 #define _IOWR(x, y, t) ((long)(IOC_INOUT | ((sizeof(t) & IOCPARM_MASK) << 16) | ((x) << 8) | (y))) 521 #endif /* !defined(FIONREAD) || !defined(FIONBIO) */ 522 523 #ifndef FIONREAD 524 #define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */ 525 #endif 526 #ifndef FIONBIO 527 #define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */ 528 #endif 529 530 /* Socket I/O Controls: unimplemented */ 531 #ifndef SIOCSHIWAT 532 #define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */ 533 #define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */ 534 #define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */ 535 #define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */ 536 #define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */ 537 #endif 538 539 /* commands for fnctl */ 540 #ifndef F_GETFL 541 #define F_GETFL 3 542 #endif 543 #ifndef F_SETFL 544 #define F_SETFL 4 545 #endif 546 547 /* File status flags and file access modes for fnctl, 548 these are bits in an int. */ 549 #ifndef O_NONBLOCK 550 #define O_NONBLOCK 1 /* nonblocking I/O */ 551 #endif 552 #ifndef O_NDELAY 553 #define O_NDELAY O_NONBLOCK /* same as O_NONBLOCK, for compatibility */ 554 #endif 555 #ifndef O_RDONLY 556 #define O_RDONLY 2 557 #endif 558 #ifndef O_WRONLY 559 #define O_WRONLY 4 560 #endif 561 #ifndef O_RDWR 562 #define O_RDWR (O_RDONLY|O_WRONLY) 563 #endif 564 565 #ifndef SHUT_RD 566 #define SHUT_RD 0 567 #define SHUT_WR 1 568 #define SHUT_RDWR 2 569 #endif 570 571 /* FD_SET used for lwip_select */ 572 #ifndef FD_SET 573 #undef FD_SETSIZE 574 /* Make FD_SETSIZE match LWIP_CONFIG_NUM_SOCKETS in socket.c */ 575 #define FD_SETSIZE MEMP_NUM_NETCONN 576 #define LWIP_SELECT_MAXNFDS (FD_SETSIZE + LWIP_SOCKET_OFFSET) 577 #define FDSETSAFESET(n, code) do { \ 578 if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \ 579 code; }} while(0) 580 #define FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\ 581 (code) : 0) 582 #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)))) 583 #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)))) 584 #define FD_ISSET(n,p) FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & (1 << (((n)-LWIP_SOCKET_OFFSET) & 7))) 585 #define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) 586 587 typedef struct fd_set 588 { 589 unsigned char fd_bits [(FD_SETSIZE+7)/8]; 590 } fd_set; 591 592 #elif FD_SETSIZE < (LWIP_SOCKET_OFFSET + MEMP_NUM_NETCONN) 593 #error "external FD_SETSIZE too small for number of sockets" 594 #else 595 #define LWIP_SELECT_MAXNFDS FD_SETSIZE 596 #endif /* FD_SET */ 597 598 /* poll-related defines and types */ 599 /* @todo: find a better way to guard the definition of these defines and types if already defined */ 600 #if !defined(POLLIN) && !defined(POLLOUT) 601 #define POLLIN 0x1 602 #define POLLOUT 0x2 603 #define POLLERR 0x4 604 #define POLLNVAL 0x8 605 /* Below values are unimplemented */ 606 #define POLLRDNORM 0x10 607 #define POLLRDBAND 0x20 608 #define POLLPRI 0x40 609 #define POLLWRNORM 0x80 610 #define POLLWRBAND 0x100 611 #define POLLHUP 0x200 612 typedef unsigned int nfds_t; 613 struct pollfd 614 { 615 int fd; 616 short events; 617 short revents; 618 }; 619 #endif 620 621 /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided 622 * by your system, set this to 0 and include <sys/time.h> in cc.h */ 623 #ifndef LWIP_TIMEVAL_PRIVATE 624 #define LWIP_TIMEVAL_PRIVATE 1 625 #endif 626 627 #if LWIP_TIMEVAL_PRIVATE 628 struct timeval { 629 long tv_sec; /* seconds */ 630 long tv_usec; /* and microseconds */ 631 }; 632 #endif /* LWIP_TIMEVAL_PRIVATE */ 633 634 #define lwip_socket_init() /* Compatibility define, no init needed. */ 635 #else /* !LWIP_LITEOS_COMPAT */ 636 #ifndef SOCK_MAX 637 #define SOCK_MAX (SOCK_RAW + 1) 638 #endif 639 640 #ifndef SOCK_TYPE_MASK 641 #define SOCK_TYPE_MASK 0xf 642 #endif 643 #endif /* !LWIP_LITEOS_COMPAT */ 644 645 #ifndef IOV_MAX 646 #ifdef UIO_MAXIOV 647 #define IOV_MAX UIO_MAXIOV 648 #else 649 #define IOV_MAX 1024 650 #endif 651 #endif 652 653 void lwip_socket_thread_init(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: initialize thread-local semaphore */ 654 void lwip_socket_thread_cleanup(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: destroy thread-local semaphore */ 655 656 #if LWIP_IPV6 657 #define LWIP_IS_IPPROTOCOL(protocol) ((protocol) == IPPROTO_IP || (protocol) == IPPROTO_IPV6 || (protocol) == 0) 658 #if PF_PACKET 659 #define LWIP_IS_VALID_DOMAIN(domain) (((domain) == AF_INET) || ((domain) == AF_INET6) || ((domain) == PF_PACKET)) 660 #else 661 #define LWIP_IS_VALID_DOMAIN(domain) ((domain) == AF_INET) || ((domain) == AF_INET6) 662 #endif 663 #else 664 #define LWIP_IS_IPPROTOCOL(protocol) ((protocol) == IPPROTO_IP || (protocol) == 0) 665 #if PF_PACKET 666 #define LWIP_IS_VALID_DOMAIN(domain) (((domain) == AF_INET) || ((domain) == PF_PACKET)) 667 #else 668 #define LWIP_IS_VALID_DOMAIN(domain) ((domain) == AF_INET) || ((domain) == AF_INET6) 669 #endif 670 #endif 671 672 #if LWIP_IPV6 673 /** 674 * @ingroup Duplicate_Address_Detection_IOCTL 675 * @brief 676 * This is a IOCTL to turn on/off Duplicate Address Detection at run time. 677 * IOCTL cmd: SIOCSIPV6DAD. 678 * 679 * @param[in] s Indicates socket index, but not used. 680 * @param[in] cmd Indicates IOCTL unique command. 681 * @param[in] argp Indicates void pointer to struct ifreq. 682 * Valid struct ifreq must have valid ifrn_name 683 * (interface name.) and ifru_ivalue 0 or 1,\n 684 * 0 indicates turnoff.\n 685 * 1 indicates turnon. 686 * 687 * @returns 688 * 0 : On success. \n 689 * Negative Value : On failure. 690 */ 691 #ifndef SIOCSIPV6DAD 692 #define SIOCSIPV6DAD _IOW('z', 0, unsigned long) /* set DAD enable/disable on netif */ 693 #endif 694 695 /** 696 * @ingroup Duplicate_Address_Detection_IOCTL 697 * @brief 698 * This is a IOCTL to get status of Duplicate Address Detection. 699 * IOCTL cmd: SIOCGIPV6DAD. 700 * 701 * 702 * @param[in] s Indicates socket index, but not used. 703 * @param[in] cmd Indicates IOCTL unique command. 704 * @param[out] argp Indicates void pointer to struct ifreq. 705 * Valid struct ifreq must have valid ifrn_name 706 * (interface name.). \n 707 * User can read value of ifru_ivalue in struct 708 * ifreq. 709 * 0 indicates turnoff.\n 710 * 1 indicates turnon. 711 * 712 * @returns 713 * 0 : On sucess. \n 714 * Negative Value : On failure. 715 */ 716 #ifndef SIOCGIPV6DAD 717 #define SIOCGIPV6DAD _IOR('z', 1, unsigned long) /* get DAD status on netif */ 718 #endif 719 720 /** 721 * @brief 722 * set DEPRECATION enable/disable on netif 723 * This is a IOCTL to turn on/off Preferred and Deprecation state facility for 724 * address at run time. 725 * IOCTL cmd: SIOCSIPV6DPCTD. 726 * 727 * @param[in] s Indicates socket index, but not used. 728 * @param[in] cmd Indicates IOCTL unique command. 729 * @param[in] argp Indicates void pointer to struct ifreq. 730 * Valid struct ifreq must have valid ifrn_name 731 * (interface name.) and ifru_ivalue 0 or 1,\n 732 * 0 indicates turnoff.\n 733 * 1 indicates turnon. 734 * 735 * @returns 736 * 0 : On sucess. \n 737 * Negative Value : On failure. 738 */ 739 740 #ifndef SIOCSIPV6DPCTD 741 #define SIOCSIPV6DPCTD _IOW('z', 2, unsigned long) 742 #endif 743 744 /* get DEPRECATION status on netif */ 745 /** 746 * @brief 747 * This is a IOCTL to get status of Duplicate Address Detection. 748 * IOCTL cmd: SIOCGIPV6DPCTD. 749 * 750 * 751 * @param[in] s Indicates socket index, but not used. 752 * @param[in] cmd Indicates IOCTL unique command. 753 * @param[out] argp Indicates void pointer to struct ifreq. 754 * Valid struct ifreq must have valid ifrn_name 755 * (interface name.). \n 756 * User can read value of ifru_ivalue in struct 757 * ifreq. 758 * 0 indicates turnoff.\n 759 * 1 indicates turnon. 760 * 761 * @returns 762 * 0 : On sucess. \n 763 * Negative Value : On failure. 764 */ 765 #ifndef SIOCGIPV6DPCTD 766 #define SIOCGIPV6DPCTD _IOR('z', 3, unsigned long) 767 #endif 768 #endif 769 770 #ifdef LWIP_LITEOS_A_COMPAT 771 int socks_poll(int sockfd, poll_table *wait); 772 int socks_ioctl(int sockfd, long cmd, void *argp); 773 int socks_close(int sockfd); 774 void socks_refer(int sockfd); 775 #endif 776 777 #if LWIP_COMPAT_SOCKETS == 2 778 /* This helps code parsers/code completion by not having the COMPAT functions as defines */ 779 #define lwip_accept accept 780 #define lwip_bind bind 781 #define lwip_shutdown shutdown 782 #define lwip_getpeername getpeername 783 #define lwip_getsockname getsockname 784 #define lwip_getpeername getpeername 785 #define lwip_setsockopt setsockopt 786 #define lwip_getsockopt getsockopt 787 #define lwip_close closesocket 788 #define lwip_connect connect 789 #define lwip_listen listen 790 #define lwip_recv recv 791 #define lwip_recvmsg recvmsg 792 #define lwip_recvfrom recvfrom 793 #define lwip_send send 794 #define lwip_sendmsg sendmsg 795 #define lwip_sendto sendto 796 #define lwip_socket socket 797 #ifndef LOSCFG_FS_VFS 798 #if LWIP_SOCKET_SELECT 799 #define lwip_select select 800 #endif 801 #if LWIP_SOCKET_POLL && !LWIP_EXT_POLL_SUPPORT 802 #define lwip_poll poll 803 #endif 804 #endif /* LOSCFG_FS_VFS */ 805 #define lwip_ioctl ioctlsocket 806 #define lwip_inet_ntop inet_ntop 807 #define lwip_inet_pton inet_pton 808 #if LWIP_FCNTL 809 #define lwip_fcntl fcntl 810 #endif 811 812 #if LWIP_DNS 813 #define lwip_gethostbyname(name) gethostbyname(name) 814 #define lwip_gethostbyname_r gethostbyname_r 815 #define lwip_freeaddrinfo freeaddrinfo 816 #define lwip_getaddrinfo getaddrinfo 817 #define lwip_getnameinfo getnameinfo 818 #endif 819 820 #if LWIP_POSIX_SOCKETS_IO_NAMES 821 #define lwip_read read 822 #define lwip_readv readv 823 #define lwip_write write 824 #define lwip_writev writev 825 #undef lwip_close 826 #define lwip_close close 827 #define closesocket(s) close(s) 828 int fcntl(int s, int cmd, ...); 829 #undef lwip_ioctl 830 #define lwip_ioctl ioctl 831 #define ioctlsocket ioctl 832 #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */ 833 #endif /* LWIP_COMPAT_SOCKETS == 2 */ 834 835 /* 836 Func Name: lwip_accept 837 */ 838 /** 839 * @ingroup socket 840 * @brief This API accepts a new connection on a socket. 841 * The accept() function extracts the first connection on the queue of pending connections, 842 creates a new socket with the same socket type protocol and address family as the specified socket, 843 and allocates a new file descriptor for that socket. 844 If the address is not a null pointer, the address of the peer for the accepted connection shall be stored 845 in the sockaddr structure pointed to by address, and the length of this address shall be stored 846 in the object pointed to by address_len. 847 If the actual length of the address is greater than the length of the supplied sockaddr structure, 848 the stored address shall be truncated. 849 If the listen queue is empty of connection requests and O_NONBLOCK is not set on the file descriptor for the socket, 850 accept() shall block until a connection is present. 851 If the listen() queue is empty of connection requests and O_NONBLOCK 852 is set on the file descriptor for the socket, accept() shall fail and set errno to [EWOULDBLOCK]. 853 * @param[in] s Specifies a socket that was created with socket(), 854 * has been bound to an address with bind(), and has issued a successful call to listen(). 855 * @param[out] address Indicates either a null pointer, or a pointer to a sockaddr structure 856 * where the address of the connecting socket shall be returned. 857 * @param[in,out] address_len Indicates either a null pointer, if address is a null pointer, or a pointer 858 * to a socklen_t object which on input 859 * specifies the length of the supplied sockaddr structure, 860 * and on output specifies the length of the stored address. 861 * 862 * @return 863 * The non-negative file descriptor of the accepted socket: On success \n 864 * -1: On failure. The errno shall be set to indicate the error, and any object pointed to by address_len 865 shall remain unchanged. \n 866 867 * 868 * @par Errors 869 * \li The accept() function fails if: 870 * - <b> [EBADF] </b>: \n The socket argument is not a valid file descriptor. 871 * - <b> [ECONNABORTED] </b>: \n A connection has been aborted. 872 * - <b> [ECONNABORTED] </b>: \n IP address of stack has changed or removed while accept() was waiting. 873 * - <b> [EFAULT] </b>: \n A valid address length provide with address pointing to invalid memory. 874 * - <b> [EINVAL] </b>: \n The socket is not listening for connections. 875 * - <b> [EINVAL] </b>: \n The address length is invalid (For example, address_len is negative). 876 * - <b> [ENFILE] </b>: \n The maximum number of sockets in the system are already open. 877 * - <b> [ENOBUFS] </b>: \n No buffer space is available. 878 * - <b> [ENOMEM] </b>: \n There was insufficient memory available to complete the operation. 879 * - <b> [EOPNOTSUPP] </b>: \n The referenced socket is not of type SOCK_STREAM. 880 * - <b> [EWOULDBLOCK]</b> : \n O_NONBLOCK is set for the socket file descriptor and 881 * no connections are present to be accepted. 882 * - <b> [EWOULDBLOCK]</b> : \n O_NONBLOCK is not set but SO_RCVTIMEO is set, and no connections are present 883 * within accept timeout. 884 885 * \li The accept() function may fail if: 886 * - <b> [EIO] </b>: \n Internal errors 887 * @par POSIX Conformance: 888 * @li Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). 889 * The following are the exceptions to conformance: 890 * - The new socket return by accept() inherit socket options such as SOF_REUSEADDR,SOF_KEEPALIVE. 891 * This behaviour may differ from other implementations. Portable programs should not rely on inheritance or 892 * non inheritance of file status flags or socket options, and always explicitly set all required flags or 893 * options on the socket returned from the accept() API. 894 * - EIO is an lwIP specific errno, not defined by POSIX. Portable programs must not 895 * use these options in applications. 896 * - If IP address of stack changes or removed due to netif_remove, while accept() is waiting, 897 * then stack might return ECONNABORTED. 898 * - If accept() called after IP address bind to socket has been removed, then accept() 899 * might block indefinitely. 900 * 901 * @note 902 * - This API does not support the PF_PACKET option. 903 * @par Related Topics 904 * connect() 905 */ 906 int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); 907 908 /* 909 Func Name: lwip_bind 910 */ 911 /** 912 * @ingroup socket 913 * @brief 914 The bind() function assigns a local socket address address to a socket identified by descriptor socket 915 that has no local socket address assigned. Sockets created with the socket() function are initially unnamed; 916 they are identified only by their address family. This API assigns the address specified by name 917 to the socket referred to 918 * by the file descriptor s. namelen specifies the size, in bytes, of the address 919 * structure pointed to by name. 920 * 921 * @param[in] s Specifies the file descriptor of the socket to be bound. 922 * @param[in] name Points to a sockaddr structure containing the address to be bound to the socket. 923 * The length and format of the address depend on the address family of the socket. 924 * @param[in] namelen Specifies the length of the sockaddr structure pointed to by the address argument. 925 * 926 * @return 927 * 0: On success \n 928 * -1: On failure. The errno is set to indicate the error. \n 929 * 930 * @par Errors 931 * @li The bind() function shall fail if: 932 * - <b> [EADDRINUSE] </b>: \n The specified address is already in use. 933 * - <b> [EADDRINUSE] </b>: \n For AF_INET/AF_INET6 socket, the port number was specified as zero 934 * in the socket address structure, but, upon attempting to bind to an ephemeral port, 935 * it was determined that all port numbers in the ephemeral port range are currently in use. 936 * - <b> [EADDRNOTAVAIL] </b>: \n The specified address is not available from the local machine. 937 * - <b> [EAFNOSUPPORT] </b>: \n The specified address is not a valid address for the address family 938 * of the specified socket. 939 * - <b> [EBADF] </b> : \n The socket argument is not a valid file descriptor. 940 * - <b> [EINVAL] </b> : \n The socket is already bound to an address, and the protocol does not support 941 * binding to a new address. 942 * - <b> [EINVAL] </b> : \n The namelen argument is not a valid length for the address family. 943 * - <b> [EINVAL] </b> : \n For PF_PACKET socket, the ifindex is out of system netif index range. 944 * - <b> [EISCONN] </b>: \n The specified socket is already connected. 945 * - <b> [ENOBUFS] </b>: \n Insufficient resources were available to complete the call. 946 * - <b> [ENODEV] </b>: \n For PF_PACKET socket, the netif can not be determined by the ifindex. 947 * - <b> [ENETDOWN] </b>: \n For PF_PACKET socket, the netif determined by the ifindex was down. 948 * - <b> [EOPNOTSUPP] </b>: \n The socket type of the specified socket does not support binding to an address. 949 950 * @par POSIX Conformance: 951 * Confirming to POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition) 952 * @note 953 * - Multiple bind call behavior: bind() call will change port binding of UDP socket. 954 * - On UDP socket will change local binding port. 955 * - On TCP socket it is not allowed, will return failure with errno EINVAL. 956 * - On AF_INET/AF_INET6 SOCK_RAW socket, it will update local IP address. 957 * - ON PF_PAKCET socket, it will change binding to new interface index. \n 958 * - AF_INET/AF_INET6 SOCK_RAW bind does not check if socket address is available or not. 959 */ 960 int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen); 961 962 /* 963 Func Name: lwip_shutdown 964 */ 965 /** 966 * @ingroup socket 967 * @brief 968 * This API is used to shut down socket send and receive operations.\n 969 * The shutdown() function shall cause all or part of a full-duplex connection on the socket associated 970 * with the file descriptor socket to be shut down. 971 * 972 * @param[in] s Specifies a file descriptor referring to the socket. 973 * @param[in] how Specifies the type of shut-down. The values are as follows: \n 974 * SHUT_RD Disables further receive operations. \n SHUT_WR: Disables further send operations. \n 975 * SHUT_RDWR: Disables further send and receive operations. \n 976 977 The shutdown() function disables subsequent send and/or receive operations on a socket, 978 depending on the value of the how argument. 979 * 980 * @return 981 * 0: On success \n 982 * -1: On failure. The errno is set to indicate the error. \n 983 * 984 * @par Errors 985 * @li The shutdown() function shall fail if: 986 * - <b> [EBADF] </b> : \n The socket argument is not a valid file descriptor. 987 * - <b> [EINPROGRESS] </b>: \n If WRITE/CONNECTING/CLOSE is in progress, lwIP may fail. 988 * - <b> [EINVAL] </b>: \n The 'how' argument is invalid. 989 * - <b> [ENOMEM] </b>: \n There was insufficient memory available to complete the operation. 990 * - <b> [ENOTCONN] </b>: \n If socket is not connected, or already shutdown. lwIP shall fail with ENOTCONN. 991 * - <b> [ENOTCONN] </b>: \n lwIP does not support half close, ENOTCONN is returned. 992 * - <b> [ENOTCONN] </b>: \n Socket is not TCP, lwIP shall fail. 993 994 * @par POSIX Conformance: 995 Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). 996 The following are the exceptions to conformance: 997 - lwIP does not support half shutdown. That is, if you try to shutdown with either SHUT_RD or SHUT_WR alone, 998 this API returns error ENOTCONN. 999 * @note 1000 * - This API does not support the PF_PACKET option. 1001 * - The listen socket does not support half shutdown. 1002 * @par Limitations 1003 * - If shutdown is called with SHUT_RDWR or SHUT_RD flag, any pending data to be received shall be cleared by lwIP, 1004 * and RST is sent to peer, application must read all data before calling SHUT_RDWR or SHUT_RD. 1005 * This behavior is a limitation of lwIP. \n 1006 * - When send is blocked, and shutdown(SHUT_RDWR) is called, the shutdown will return EINPROGRESS (115). 1007 */ 1008 int lwip_shutdown(int s, int how); 1009 1010 /* 1011 Func Name: lwip_getpeername 1012 */ 1013 /** 1014 * @ingroup socket 1015 * @brief 1016 * The getpeername() API returns the address of the peer connected to the socket 's', in the buffer pointed to by name. 1017 * Initialize the namelen argument to indicate the amount of space pointed to by the name parameter. 1018 * On return it contains the actual size, in bytes, of the name returned. 1019 * The name is truncated if the buffer provided is too small. 1020 * 1021 * @param[in] s Specifies the file descriptor referring to the connected socket. 1022 * @param[out] name Indicates the pointer to the sockaddr structure of remote peer. 1023 * @param[in,out] namelen Specifies the size of name structure. 1024 * 1025 * @return 1026 * 0: On success \n 1027 * -1: On failure. The errno is set to indicate the error. \n 1028 * @par Errors 1029 * @li The getpeername() function fails if: 1030 * - <b> [EBADF] </b>: The socket argument is not a valid file descriptor. 1031 * - <b> [EINVAL] </b>: The name or namelen are NULL, then EINVAL is returned. 1032 * - <b> [ENOTCONN] </b>: The socket is not connected or otherwise has not had the peer pre-specified. 1033 * - <b> [EOPNOTSUPP] </b>: The operation is not supported for the socket protocol. 1034 1035 * @par POSIX Conformance: 1036 * Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). 1037 * The following are the exceptions to conformance: 1038 * - lwIP does not check if connection-mode socket have been shutdown, and does not return failure with errno [EINVAL]. 1039 * 1040 * @note 1041 * - For PF_PACKET socket type, name should be pointing to sockaddr_ll type or memory of size struct sockaddr_ll 1042 * 1043 * @par Related Topics 1044 * getsockname() 1045 */ 1046 int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen); 1047 1048 /* 1049 Func Name: lwip_getsockname 1050 */ 1051 /** 1052 * @ingroup socket 1053 * @brief 1054 * This API returns the current address to which the socket 's' is bound, in the buffer pointed to by the name 1055 * parameter. 1056 * Initialize the namelen argument to indicate the amount of space (in bytes) pointed to by the name parameter. 1057 * The returned address is truncated if the buffer provided is too small. 1058 * 1059 * @param[in] s Specifies the file descriptor referring to connected socket. 1060 * @param[out] name Indicates a pointer to sockaddr structure of local peer. 1061 * @param[in,out] namelen Specifies the size of name structure. 1062 * 1063 * @return 1064 * 0: On success \n 1065 * -1: On failure. The errno is set to indicate the error. \n 1066 * @par Errors 1067 * @li The getsockname() function shall fail if: 1068 * - <b> [EBADF] </b>: \n The socket argument is not a valid file descriptor. 1069 * - <b> [EINVAL] </b>: \n If name or namelen are NULL, then this errno will be set. 1070 * - <b> [EOPNOTSUPP] </b>: \n The operation is not supported for this socket's protocol. 1071 * For PF_PACKET/SOCK_RAW sockets, this error is returned. 1072 1073 1074 * @par POSIX Conformance: 1075 * Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). 1076 * The following are the exceptions to conformance: 1077 * - lwIP does not check if connection-mode socket have been shutdown, and does not return failure with errno [EINVAL]. 1078 * @note 1079 * \n 1080 * - For PF_PACKET socket type, name should be pointing to sockaddr_ll type or memory of size struct sockaddr_ll 1081 * 1082 * @par Related Topics 1083 * getpeername() 1084 */ 1085 int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen); 1086 1087 /* 1088 Func Name: lwip_getsockopt 1089 */ 1090 /** 1091 * @ingroup socket 1092 * @brief 1093 * This API is used to get options set on a socket. This API retrieves the value for the option specified 1094 * by the optname argument for the socket 1095 * specified by sockfd. If the size of the optval is greater than optlen, the value stored in the object 1096 * pointed to by the optval argument is silently truncated. 1097 1098 * 1099 * @param[in] s Specifies a socket file descriptor. 1100 * @param[in] level Specifies the protocol level at which the option resides. 1101 * @param[in] optname Specifies a single option to be retrieved. 1102 * @param[out] optval Indicates an address to store option value. 1103 * @param[in,out] optlen Specifies the size of the option value. 1104 * 1105 * @return 1106 * 0: On success \n 1107 * -1: On failure. The errno is set to indicate the error. \n 1108 1109 * 1110 * @par Errors 1111 * @li The getsockopt() function fails in the following conditions: 1112 * - <b> [EBADF] </b>: \n The socket argument is not a valid file descriptor. 1113 * - <b> [EFAULT] </b>: \n If opt or optlen are NULL,option or option length is incorrect. 1114 * - <b> [EINVAL] </b>: \n If option length is incorrect for specified opt. 1115 * - <b> [EINVAL] </b>: \n The specified option is invalid at the specified socket level. 1116 * - <b> [EINVAL] </b>: \n The specified optval is invalid for specified opt. 1117 * - <b> [EINVAL] </b>: \n The specified socket is already closed or has been disconnected. 1118 * - <b> [ENOMEM] </b>: \n There was insufficient memory available to complete the operation. 1119 * - <b> [ENOPROTOOPT] </b>: \n The option is not supported by the protocol. 1120 1121 * @par POSIX Conformance: 1122 Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). The following are the exceptions 1123 to conformance: 1124 - lwIP does not check if connection-mode socket have been shutdown, and does not return failure with errno [EINVAL]. 1125 * @note 1126 * - The following protocol levels are supported: 1127 * - SOL_SOCKET 1128 * - IPPROTO_IP 1129 * - IPPROTO_TCP 1130 * - IPPROTO_RAW 1131 * - IPPROTO_IPV6 1132 * - IPPROTO_UDPLITE 1133 * - The following options are supported under SOL_SOCKET:\n 1134 * - SO_ACCEPTCONN 1135 * - SO_BROADCAST 1136 * - SO_ERROR 1137 * - SO_KEEPALIVE 1138 * - SO_SNDTIMEO 1139 * - SO_RCVTIMEO 1140 * - SO_RCVBUF 1141 * - SO_SNDBUF 1142 * - SO_REUSEADDR 1143 * - SO_TYPE 1144 * - SO_NO_CHECK 1145 * - SO_BINDTODEVICE 1146 * - SO_DONTROUTE 1147 * - SO_LINGER 1148 * For SO_SNDTIMEO, SO_RCVTIMEO, SO_RCVBUF, the macros LWIP_SO_SNDTIMEO, LWIP_SO_RCVTIMEO, 1149 * and LWIP_SO_RCVBUF must be defined at compile time.\n 1150 * For SO_REUSEADDR, the macro SO_REUSE must be defined at compile time.\n 1151 * For SO_BINDTODEVICE, the macro 1152 * LWIP_SO_BINDTODEVCE should have been defined at compile time. For SO_DONTROUTE, 1153 * the macro LWIP_SO_DONTROUTE should have been defined at compile time. 1154 * For SO_SNDBUF, the macro LWIP_SO_SNDBUF must be defined at compile time.\n 1155 * - The following options are supported under IPPROTO_IP: 1156 * - IP_MULTICAST_TTL 1157 * - IP_MULTICAST_LOOP 1158 * - IP_MULTICAST_IF 1159 * - IP_HDRINCL 1160 * - IP_TTL 1161 * - IP_TOS 1162 * If IP_HDRINCL is set , other options like IP_TTL and IP_TOS will be still able to set but will be effective 1163 * only when IP_HDRINCL is unset.\n 1164 * - The following options are supported under IPPROTO_TCP: 1165 * - TCP_NODELAY 1166 * - TCP_MAXSEG 1167 * - TCP_KEEPIDLE 1168 * - TCP_KEEPINTVL 1169 * - TCP_KEEPCNT 1170 * - TCP_INFO 1171 * - TCP_QUEUE_SEQ 1172 * For TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT, the macro LWIP_TCP_KEEPALIVE should have been 1173 * defined at compile time. 1174 * - SO_ERROR is not supported when socket is SOCK_RAW type. 1175 * For TCP_INFO, the macro LWIP_TCP_INFO should have been defined at compile time.\n 1176 * - For TCP_INFO, Only tcpi_state, tcpi_retransmits, tcpi_probes, tcpi_backoff, tcpi_options, tcpi_rto, 1177 * tcpi_snd_mss, tcpi_rcv_mss, tcpi_unacked, 1178 * tcpi_rtt, tcpi_rttvar, tcpi_snd_ssthresh, tcpi_snd_cwnd, tcpi_reordering in 1179 * struct tcp_info are supported. Other fields are kept as 0. \n 1180 * - The following options are supported under IPPROTO_RAW: 1181 * - IPV6_CHECKSUM: Checksum option to the offset for raw socket for updating the checksum. \n 1182 * - The following options are supported under IPPROTO_IPV6: 1183 * - IPV6_V6ONLY: Sets the ipv6 option. 1184 * - IPV6_CHECKSUM: Checksum option to the offset for raw socket for updating the checksum. 1185 * - IPV6_UNICAST_HOPS:To get the hop limit value used in outgoing unicast IPv6 packets Only supported 1186 * in get implementation. 1187 * - IPV6_MULTICAST_HOPS: To get the hop limit value used for outgoing multicast packets, only for UDP. 1188 * - IPV6_MULTICAST_IF: To get the netif used for outgoing multicast packets, only for UDP. 1189 * - IPV6_MULTICAST_LOOP: To get the local loopback of multicast datagrams, only for UDP. 1190 * - The following options are supported under IPPROTO_UDPLITE:\n 1191 * - UDPLITE_SEND_CSCOV \n 1192 * - UDPLITE_RECV_CSCOV\n 1193 1194 * 1195 * 1196 * @par Related Topics \n 1197 * setsockopt() 1198 */ 1199 int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen); 1200 1201 /* 1202 Func Name: lwip_setsockopt 1203 */ 1204 /** 1205 * @ingroup socket 1206 * @brief 1207 The setsockopt() function sets the option specified by the option_name argument, at the protocol level specified 1208 by the level argument, to the value pointed to by the option_value argument for the socket associated 1209 with the file descriptor specified by the socket argument. 1210 1211 The level argument specifies the protocol level at which the option resides. To set options at the socket level, 1212 specify the level argument as SOL_SOCKET. To set options at other levels, supply the appropriate level identifier 1213 for the protocol controlling the option. For example, to indicate that an option is interpreted 1214 by the TCP (Transport Control Protocol), set level to IPPROTO_TCP. 1215 1216 The option_name argument specifies a single option to set. If option_name is equal to SO_RCVTIMEO or SO_SNDTIMEO 1217 and the implementation supports setting the option, the struct timeval pointed to by option_value is rounded up 1218 to align with the resolution of the clock being used. If setsockopt() is called with option_name equal 1219 to SO_ACCEPTCONN, SO_ERROR, or SO_TYPE, the setsockopt fails. 1220 * 1221 * @param[in] s Specifies a socket file descriptor. 1222 * @param[in] level Specifies the protocol level at which the option resides. 1223 * @param[in] option_name Specifies a single option to set. 1224 * @param[out] option_value Indicates the pointer to the option value. 1225 * @param[in] option_len Specifies the size of option value. 1226 * 1227 * @return 1228 * 0: On success \n 1229 * -1: On failure. The errno is set to indicate the error. \n 1230 1231 * @par Errors 1232 * @li The setsockopt() function fails in the following conditions: 1233 * - <b> [EBADF] </b>: \n The socket argument is not a valid file descriptor. 1234 * - <b> [EDOM] </b>: \n The send and receive timeout values are too big to fit into the timeout fields 1235 * in the socket structure. 1236 * - <b> [EFAULT] </b>: \n If optval is NULL pointer, lwIP fails. 1237 * - <b> [EINVAL] </b>: \n If for PF_PACKET socket type, level is neither SOL_PACKET nor SOL_SOCKET, lwIP fails. 1238 * - <b> [EINVAL] </b>: If for PF_PACKET socket type, level is neither SOL_PACKET nor SOL_SOCKET, lwIP shall fail. 1239 * - <b> [EINVAL] </b>: \n If option_len does not match optval for corresponding option_name, lwIP fails. 1240 * - <b> [EINVAL] </b>: \n If the send and receive timeout values are smaller than 10000 microseconds, lwIP fails. 1241 * - <b> [ENOENT] </b>: \n The option is SO_DETACH_FILTER while no previous socket filter was attached. 1242 * - <b> [ENOMEM] </b>: \n There was insufficient memory available for the operation to complete. 1243 * - <b> [ENOPROTOOPT] </b>: \n The option is not supported by the protocol. 1244 * @par POSIX Conformance: 1245 Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). The following are the exceptions 1246 to conformance: 1247 - If connection oriented socket is shutdown, setsockopt does not check for this and does not return failure 1248 with errno EINVAL as expected by POSIX. 1249 - If socket option is INVALID at specified socket level, setsockopt returns failure with errno set to ENOPROTOOPT, 1250 which is not in conformance to POSIX. 1251 - setsockopt does not check if connection is already connected for the specified options if can not be set 1252 while socket is connected. 1253 * @note 1254 * - The following protocol levels are supported: 1255 * - SOL_SOCKET 1256 * - IPPROTO_IP 1257 * - IPPROTO_IPV6 1258 * - IPPROTO_TCP 1259 * - IPPROTO_RAW 1260 * - IPPROTO_UDPLITE 1261 * - The following options are supported under SOL_SOCKET: 1262 * - SO_BROADCAST 1263 * - SO_KEEPALIVE 1264 * - SO_LINGER 1265 * - SO_SNDTIMEO 1266 * - SO_RCVTIMEO 1267 * - SO_RCVBUF 1268 * - SO_SNDBUF 1269 * - SO_ATTACH_FILTER 1270 * - SO_DETACH_FILTER 1271 * - SO_BINDTODEVICE 1272 * - SO_DONTROUTE 1273 * - SO_REUSEADDR 1274 * - SO_NO_CHECK 1275 * 1276 * For SO_ATTACH_FILTER, SO_DETACH_FILTER, 1277 * the macro LWIP_SOCKET_FILTER should have been defined at compile time.\n 1278 * SO_ATTACH_FILTER: \n 1279 * - LSF_MSH are not supported, due to which LSF_LDX hack for loading IP header length wont be supported. Hence, \n 1280 * Following mode of filter is not supported: \n 1281 * LSF_LDX+LSF_B+LSF_MSH X <- 4*(P[k:1]&0xf)\n 1282 * - Only PF_PACKET RAW socket supports SO_ATTACH_FILTER and SO_DETACH_FILTER now.\n 1283 * - Caller shall ensure the validity of the attached filter.\n 1284 * For SO_SNDTIMEO, SO_RCVTIMEO, SO_RCVBUF, the macros LWIP_SO_SNDTIMEO, LWIP_SO_RCVTIMEO 1285 * and LWIP_SO_RCVBUF must be defined at compile time. \n 1286 * For SO_DONTROUTE, the macro LWIP_SO_DONTROUTE should have been defined at compile time, 1287 * and RT_SCOPE_HOST is not supported. \n 1288 * For SO_SNDBUF, the macro LWIP_SO_SNDBUF must be defined at compile time.\n 1289 * For SO_REUSEADDR, the macro SO_REUSE must be defined at compile time.\n 1290 * SO_REUSEADDR: \n 1291 * - SO_REUSEADDR does not distribute datagrams evenly across the receiving threads.\n 1292 * Only TCP socket in listen or closed states supports SO_SNDBUF.\n 1293 * - The following options are supported under IPPROTO_IP: 1294 * - IP_ADD_MEMBERSHIP 1295 * - IP_DROP_MEMBERSHIP 1296 * - IP_MULTICAST_TTL 1297 * - IP_MULTICAST_LOOP 1298 * - IP_MULTICAST_IF 1299 * - IP_HDRINCL 1300 * - IP_TTL 1301 * - IP_TOS 1302 * - The following options are supported under IPPROTO_IPV6: 1303 * - IPV6_V6ONLY 1304 * - IPV6_CHECKSUM 1305 * - IPV6_MULTICAST_HOPS: To set the hop limit value used for outgoing multicast packets, only for UDP. 1306 * - IPV6_MULTICAST_IF: To set the netif used for outgoing multicast packets, only for UDP. 1307 * - IPV6_MULTICAST_LOOP: Enable or disable local loopback of multicast datagrams, only for UDP. 1308 * -IPV6_JOIN_GROUP(IPV6_ADD_MEMBERSHIP) 1309 * If the interface index is specified as 0, stack will not handle further, application has to give the valid index. 1310 * -IPV6_LEAVE_GROUP(IPV6_DROP_MEMBERSHIP) 1311 * - The following options are supported under IPPROTO_RAW: 1312 * - IPV6_CHECKSUM 1313 * - The following options are supported under IPPROTO_TCP: 1314 * - TCP_NODELAY 1315 * - TCP_MAXSEG 1316 * - TCP_KEEPIDLE 1317 * - TCP_KEEPINTVL 1318 * - TCP_KEEPCNT 1319 * For TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT, the macro LWIP_TCP_KEEPALIVE must be defined 1320 * at compile time. 1321 * - The following options are supported under IPPROTO_UDPLITE the options supported are: 1322 * - UDPLITE_SEND_CSCOV 1323 * - UDPLITE_RECV_CSCOV\n 1324 * For IPPROTO_UDPLITE, the macro LWIP_UDPLITE must be defined at compile time.\n 1325 1326 * @par Related Topics 1327 * getsockopt() 1328 */ 1329 int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen); 1330 1331 /* 1332 Func Name: lwip_close 1333 */ 1334 /** 1335 * @ingroup socket 1336 * @brief 1337 * This API is used to close the socket. 1338 * If O_NONBLOCK is not set and if there is data on the module's write queue, close() waits for an unspecified time 1339 * for any output to drain before dismantling the STREAM. 1340 * If the O_NONBLOCK flag is set, close() does not wait for output to drain, and dismantles the STREAM immediately. 1341 * 1342 * @param[in] s Specifies a socket file descriptor. 1343 * 1344 * @return 1345 * 0: On success \n 1346 * -1: On failure. The errno is set to indicate the error. \n 1347 * @par Errors 1348 * @li The close() function shall fail if: 1349 * - <b> [EBADF] </b>: \n The files argument is not a open file descriptor. Invalid file descriptor. 1350 * 1351 * @par Note 1352 * The API must not be called concurrently with other BSD API on the same socket, 1353 * because this scenario maybe causes other BSD API to return with unexpected behavior. 1354 * 1355 * @par POSIX Conformance: 1356 Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). The following are the exceptions 1357 to conformance: 1358 - Does not support SO_LINGER socket option. 1359 * 1360 * 1361 */ 1362 int lwip_close(int s); 1363 1364 /* 1365 Func Name: lwip_connect 1366 */ 1367 /** 1368 * @ingroup socket 1369 * @brief 1370 The connect() function shall attempt to make a connection on a connection-mode socket or to set or reset 1371 the peer address of a connectionless-mode socket. 1372 \n 1373 Specifies the length of the sockaddr structure pointed to by the address argument. \n 1374 1375 1376 If the socket has not already been bound to a local address, connect() shall bind it to an address 1377 which is an unused local address. 1378 1379 If the initiating socket is not connection-mode, then connect() shall set the socket's peer address, 1380 and no connection is made. For SOCK_DGRAM sockets, the peer address identifies where all datagrams are sent 1381 on subsequent send() functions, and limits the remote sender for subsequent recv() functions. 1382 1383 If the initiating socket is connection-mode, then connect() shall attempt to establish a connection 1384 to the address specified by the address argument. If the connection cannot be established immediately 1385 and O_NONBLOCK is not set for the file descriptor for the socket, connect() shall block for up to an unspecified timeout 1386 interval until the connection is established. If the timeout interval expires before the connection is established, 1387 connect() shall fail and the connection attempt shall be aborted. 1388 1389 If the connection cannot be established immediately and O_NONBLOCK is set for the file descriptor for the socket, 1390 connect() shall fail and set errno to [EINPROGRESS], but the connection request shall not be aborted, 1391 and the connection shall be established asynchronously. 1392 1393 * 1394 * @param[in] s Specifies a socket file descriptor. 1395 * @param[in] name Specifies a pointer to the sockaddr structure which identifies the connection. 1396 * @param[in] namelen Specifies the size of name structure. 1397 * 1398 * 1399 * @return 1400 * 0: On success \n 1401 * -1: On failure \n 1402 * @par Errors 1403 * @li The connect() function shall fail if: 1404 * - <b> [EACCES] </b>: \n The user tried to connect to a broadcast address without having 1405 * the socket broadcast flag enabled. 1406 * - <b> [EADDRNOTAVAIL] </b>: \n For AF_INET/AF_INET6 socket, the socket had not previously been bound 1407 * to an address and, upon attempting to bind it to an ephemeral port, it was determined that all port numbers 1408 * in the ephemeral port range are currently in use. 1409 * - <b> [EAFNOSUPPORT] </b>: \n The passed address did not have the correct address family in its sa_family field. 1410 * - <b> [EALREADY] </b>: \n The socket is nonblocking and a previous connection attempt has not yet been completed. 1411 * - <b> [EBADF] </b>: \n The socket argument is not a valid file descriptor. 1412 * - <b> [ECONNREFUSED] </b>: \n The target address was not listening for connections 1413 * or refused the connection request. 1414 * - <b> [ECONNRESET] </b>: \n Remote host reset the connection request. 1415 * - <b> [EINPROGRESS] </b>: \n O_NONBLOCK is set for the file descriptor for the socket and the connection 1416 * cannot be immediately established; the connection shall be established asynchronously. 1417 * - <b> [EINVAL] </b>: \n The address_len argument is not a valid length for the address family. 1418 * - <b> [EAFNOSUPPORT] </b>: \n The specified address is not a valid address for the address family 1419 * of the specified socket. 1420 * - <b> [EISCONN] </b>: \n The specified socket is connection-mode and is already connected. 1421 * - <b> [ENETUNREACH] </b>: \n No route to the network is present. 1422 * - <b> [ENOBUFS] </b>: \n No buffer space is available. 1423 * - <b> [EOPNOTSUPP] </b>: \n The referenced socket is not of domain AF_INET. 1424 * - <b> [EOPNOTSUPP] </b>: \n The socket is listening and cannot be connected. 1425 * - <b> [ETIMEDOUT] </b>: \n The attempt to connect timed out before a connection was made. 1426 1427 1428 * @par POSIX Conformance: 1429 Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). The following are the exceptions 1430 to conformance: 1431 - lwIP does not check if specified address has a different type than the socket bound to the specified peer address. 1432 Behavior is unspecified. 1433 */ 1434 int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen); 1435 1436 /* 1437 Func Name: lwip_listen 1438 */ 1439 /** 1440 * @ingroup socket 1441 * @brief 1442 * This API is used to set a socket into listen mode. 1443 * This API marks the socket referred to by sockfd as a passive socket. That is, as a socket that will be used 1444 * to accept incoming connection requests using accept(). 1445 * 1446 * @param[in] s Specifies a file descriptor that refers to a socket of type SOCK_STREAM. 1447 * @param[in] backlog Defines the maximum length to which the queue of pending connections for sockfd may grow. 1448 * If a connection request arrives when the queue is full, the client may receive an error 1449 * with an indication of ECONNREFUSED or, if the underlying protocol supports retransmission, 1450 * the request may be ignored so that a later reattempt at connection succeeds. 1451 * 1452 * @par Errors 1453 * @li The listen() function shall fail if: 1454 * - <b> [EBADF] </b>: \n The socket argument is not a valid file descriptor. 1455 * - <b> [EDESTADDRREQ] </b>: \n The socket is not bound to a local address, and the protocol does not support 1456 * listening on an unbound socket. 1457 * - <b> [EINVAL] </b>: \n The socket is in state which is not acceptable for listen. 1458 * - <b> [ENOBUFS] </b>: \n Insufficient resources are available in the system to complete the call. 1459 * - <b> [EOPNOTSUPP] </b>: \n The socket protocol does not support listen(). 1460 * 1461 * @return 1462 * 0: On success \n 1463 * -1: On failure. The errno is set to indicate the error. \n 1464 * @par POSIX Conformance: 1465 POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition) 1466 * @note 1467 * - Maximum value of backlog is 16, and minimum value of backlog is 0. 1468 * - If backlog value is 0 or less than zero, backlog value of 1 is used. 1469 * - This API does not support the PF_PACKET socket. 1470 * - lwIP does not support auto binding in listen operation, so bind() must be called before listen(). 1471 * - The listen() API supports multiple calls. If socket is already listening, it will update listen backlog. 1472 New backlog value shall be applicable only for new incoming connection requests. 1473 1474 */ 1475 int lwip_listen(int s, int backlog); 1476 1477 /* 1478 Func Name: lwip_recv 1479 */ 1480 /** 1481 * @ingroup socket 1482 * @brief 1483 * This API is used to recieve a message from connected socket. The recv() function shall receive a message 1484 * from a connection-mode or connectionless-mode socket. It is normally used with connected sockets because 1485 * it does not permit the application to retrieve the source address of received data. 1486 * If no messages are available at the socket and O_NONBLOCK is not set on the socket's file descriptor, 1487 * recv() shall block until a message arrives. If no messages are available at the socket and O_NONBLOCK is set 1488 * on the socket's file descriptor, recv() shall fail and set errno to [EWOULDBLOCK]. 1489 * 1490 * @param[in] socket Specifies the socket file descriptor. 1491 * @param[in] buffer Points to a buffer where the message should be stored. 1492 * @param[in] length Specifies the length in bytes of the buffer pointed to by the buffer argument. 1493 * @param[in] flags Specifies the type of message reception. 1494 * Values of this argument are formed by logically OR'ing zero or more of the following 1495 values: \n 1496 MSG_PEEK : Peeks at an incoming message. The data is treated as unread and the next recv() 1497 or similar function shall still return this data. \n 1498 MSG_DONTWAIT : Enables nonblocking operation; if the operation would block, the call fails 1499 with the error EAGAIN or EWOULDBLOCK. \n 1500 MSG_NOSIGNAL : Disables raising of SIGPIPE on stream sockets when the other end 1501 disappears. \n 1502 * 1503 * @return 1504 * The length of the message in bytes. : On success. If no messages are available to be received and the peer 1505 * has performed an orderly shutdown, recv() returns 0. \n 1506 * -1: On failure. The errno is set to indicate the error. 1507 1508 * @par Errors 1509 * @li The recv() function fails if: 1510 * - <b> [EBADF] </b>: \n The socket argument is not a valid file descriptor. 1511 * - <b> [ECONNRESET] </b>: \n A connection was forcibly closed by a peer. 1512 * - <b> [EINVAL]</b>: \n Invalid input parameters. If mem, len is null or flags is less than zero, 1513 * lwIP returns failure. 1514 * - <b> [ENOBUFS] </b>: \n Insufficient resources were available in the system to perform the operation. 1515 * - <b> [ENOMEM] </b>: \n Insufficient memory was available to fulfil the request. 1516 * - <b> [ENOTCONN] </b>: \n A receive is attempted on a connection-mode socket that is not connected. 1517 * - <b> [EOPNOTSUPP] </b>: \n Some bit in the flags argument is unsupported for the socket type. 1518 * - <b> [EWOULDBLOCK] </b>: \n The socket's file descriptor is marked O_NONBLOCK or MSG_DONTWAIT flag is set 1519 * and no data is waiting to be received. 1520 * - <b> [EWOULDBLOCK] </b>: \n The socket was not marked with O_NONBLOCK, but set with option SO_RCVTIMEO, 1521 * and elapsed time is more than timeout value. 1522 1523 * @li The recv() function may fail if: 1524 * - <b> [EIO]</b>: \n Internal errors. 1525 1526 1527 @par POSIX Conformance: 1528 Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). The following are the exceptions 1529 to conformance: 1530 - For UDP MSG_PEEK is not suported and data is discarded even if it is set. 1531 - MSG_OOB, MSG_WAITALL flags are not supported. 1532 * 1533 * @note 1534 * - TCP receive buffer is a list, which holds the segement received from peer. 1535 * If application is calling recv to get the data, then it just tries to get the 1536 * first entry from the list and gives back to application. This doesn't get recursively 1537 * from list to fill the complete user buffer. \n 1538 * - lwIP updates this receive buffer list when it gets the next expected segment. 1539 * If there is any out of order segment which is next to the received segment, 1540 * lwIP merges the segments and puts that as one segment on to the receive buffer list. 1541 * - If the apps don't read the packet form the socket and the recv buffered 1542 * packets up to MAX_MBOX_SIZE, the incoming packet may be discard by lwIP and cause 1543 * retransmission for tcp connection.\n 1544 * - MSG_PEEK is not supported for UDP or RAW sockets. 1545 * - UDP or RAW does not report memory allocation failure if memory allocation failed for received packet. 1546 * - Instead of MSG_WAITALL, MSG_DONTWAIT is supported. 1547 * - SO_RECVTIMEO socket option is set, and socket is not marked as O_NONBLOCK, (nonblocking), and non data is received 1548 * for timeout duration on socket, error is returned with ETIMEDOUT set. 1549 * - For TCP connection, when RST is received after FIN, this API will return 0 to indicate FIN, then return -1 1550 * and set errno to ECONNRESET for RST. 1551 * - For TCP connection, when data is received and RST is recevied together (push, ack, rst) flag is set then 1552 * the data will be lost and RST will be processed. 1553 * This API is not thread-safe. 1554 * @par Related Topics 1555 * read() 1556 * recvfrom() 1557 */ 1558 ssize_t lwip_recv(int s, void *mem, size_t len, int flags); 1559 1560 /* 1561 Func Name: lwip_read 1562 */ 1563 /** 1564 * @ingroup socket 1565 * @brief 1566 * The read() function shall attempt to read nbyte bytes from the file associated with the open file descriptor, 1567 * fildes, into the buffer pointed to by buf. The behavior of multiple concurrent reads on the same device/socket 1568 * is unspecified. 1569 Before any action described below is taken, and if nbyte is zero, the read() function may detect and return errors 1570 as described below. In the absence of errors, or if error detection is not performed, the read() function 1571 shall return zero and have no other results. 1572 If no messages are available at the socket and O_NONBLOCK is not set on the socket's file descriptor, recv() shall block 1573 until a message arrives. 1574 If no messages are available at the socket and O_NONBLOCK is set on the socket's file descriptor, recv() shall fail 1575 and set errno to [EWOULDBLOCK]. 1576 For message-based sockets, such as SOCK_DGRAM and SOCK_SEQPACKET, the entire message shall be read 1577 in a single operation. If a message is too long to fit in the supplied buffer, the excess bytes shall be discarded. 1578 1579 * 1580 * @param[in] s Specifies a socket file descriptor. 1581 * @param[out] mem Specifies the mem to store the received data. 1582 * @param[in] len Specifies the len of data to receive. 1583 * 1584 * @return 1585 * Number of bytes received: On success. \n 1586 * -1: On failure. \n 1587 * 1588 * @par Errors 1589 * @li The read() function fails if: 1590 * - <b> [EBADF] </b>: \n The socket argument is not a valid file descriptor. 1591 * - <b> [ECONNRESET] </b>: \n A connection was forcibly closed by a peer. 1592 * - <b> [EINVAL]</b>: \n Invalid input parameters. If mem, len is null or flags is less than zero, 1593 * lwIP returns failure. 1594 * - <b> [ENOBUFS] </b>: \n Insufficient resources were available in the system to perform the operation. 1595 * - <b> [ENOMEM] </b>: \n Insufficient memory was available to fulfil the request. 1596 * - <b> [ENOTCONN] </b>: \n A receive is attempted on a connection-mode socket that is not connected. 1597 * - <b> [EWOULDBLOCK] </b>: \n The socket's file descriptor is marked O_NONBLOCK or MSG_DONTWAIT flag is set 1598 * and no data is waiting to be received. 1599 * - <b> [EWOULDBLOCK] </b>: \n The socket was not marked with O_NONBLOCK, but set with option SO_RCVTIMEO, 1600 * and elapsed time is more than timeout value. 1601 * @li The read() function may fail if: 1602 * - <b> [EIO]</b>: \n Internal errors. 1603 * @par POSIX Conformance: 1604 Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). The following are the exceptions 1605 to conformance: 1606 * @par Related Topics 1607 * recv() \n 1608 * recvfrom() 1609 1610 * 1611 */ 1612 ssize_t lwip_read(int s, void *mem, size_t len); 1613 1614 /* 1615 Func Name: lwip_readv 1616 */ 1617 /** 1618 * @ingroup socket 1619 * @brief 1620 * The readv() function shall be equivalent to read(), except as described below. The readv() function shall place 1621 * the input data into the iovcnt buffers specified by the members of the iov array: iov[0], iov[1], ..., 1622 * iov[ iovcnt-1]. The iovcnt argument is valid if greater than 0 and less than or equal to {IOV_MAX}. \n 1623 * Each iovec entry specifies the base address and length of an area in memory where data should be placed. 1624 * The readv() function shall always fill an area completely before proceeding to the next. 1625 * If no messages are available at the socket and O_NONBLOCK is not set on the socket's file descriptor, readv() 1626 * shall block until a message arrives. 1627 * If no messages are available at the socket and O_NONBLOCK is set on the socket's file descriptor, readv() shall 1628 * fail and set errno to [EWOULDBLOCK]. 1629 * 1630 * @param[in] s Specifies a file descriptor. 1631 * @param[in] iov Indicates buffers of data. 1632 * @param[in] iovcnt Indicates the number of buffers. 1633 * 1634 * @par Errors 1635 * @li The readv() function fails if: 1636 * - <b> [EBADF] </b>: \n The socket argument is not a valid file descriptor. 1637 * - <b> [ECONNRESET] </b>: \n A connection was forcibly closed by a peer. 1638 * - <b> [EINVAL]</b>: \n Invalid input parameters. 1639 * - <b> [ENOBUFS] </b>: \n Insufficient resources were available in the system to perform the operation. 1640 * - <b> [ENOMEM] </b>: \n Insufficient memory was available to fulfil the request. 1641 * - <b> [ENOTCONN] </b>: \n A receive is attempted on a connection-mode socket that is not connected. 1642 * - <b> [EWOULDBLOCK] </b>: \n The socket's file descriptor is marked O_NONBLOCK or MSG_DONTWAIT flag is set 1643 * and no data is waiting to be received. 1644 * - <b> [EWOULDBLOCK] </b>: \n The socket was not marked with O_NONBLOCK, but set with option SO_RCVTIMEO, 1645 * and elapsed time is more than timeout value. 1646 * @li The readv() function may fail if: 1647 * - <b> [EIO]</b>: \n Internal errors. 1648 * @par POSIX Conformance: 1649 * Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). 1650 * @par Related Topics 1651 * read() 1652 */ 1653 ssize_t lwip_readv(int s, const struct iovec *iov, int iovcnt); 1654 1655 /* 1656 Func Name: lwip_recvfrom 1657 */ 1658 /** 1659 * @ingroup socket 1660 * @brief 1661 * The recvfrom() function shall receive a message from a connection-mode or connectionless-mode socket. 1662 * It is normally used with connectionless-mode sockets because it permits the application to retrieve the source address 1663 * of received data. 1664 The function shall return the length of the message written to the buffer pointed to by the buffer argument. 1665 For message-based sockets, such as [RS] [Option Start] SOCK_RAW, [Option End] SOCK_DGRAM, and SOCK_SEQPACKET, 1666 the entire message shall be read in a single operation. If a message is too long to fit in the supplied buffer, 1667 the excess bytes shall be discarded. 1668 1669 For stream-based sockets, such as SOCK_STREAM, message boundaries shall be ignored. In this case, data shall be 1670 returned to the user as soon as it becomes available, and no data shall be discarded. 1671 1672 Not all protocols provide the source address for messages. If the address argument is not a null pointer 1673 and the protocol provides the source address of messages, the source address of the received message shall be stored 1674 in the sockaddr structure pointed to by the address argument, and the length of this address shall be stored 1675 in the object pointed to by the address_len argument. 1676 1677 If the actual length of the address is greater than the length of the supplied sockaddr structure, the stored address 1678 shall be truncated. 1679 1680 If no messages are available at the socket and O_NONBLOCK is not set on the socket's file descriptor, recvfrom() 1681 shall block until a message arrives. If no messages are available at the socket and O_NONBLOCK is set 1682 on the socket's file descriptor, recvfrom() shall fail and set errno to [EWOULDBLOCK]. 1683 1684 * @param[in] s Specifies the socket file descriptor. 1685 * @param[out] mem Points to the memory where the message should be stored. 1686 * @param[in] len Specifies the length in bytes of the buffer pointed to by the buffer argument. 1687 * @param[in] flags Specifies the type of message reception. 1688 * Values of this argument are formed by logically OR'ing zero or more of the following 1689 values: \n 1690 MSG_PEEK : Peeks at an incoming message. The data is treated as unread and the next recv() 1691 or similar function shall still return this data. \n 1692 MSG_DONTWAIT : Enables nonblocking operation; if the operation would block, the call fails 1693 with the error EAGAIN or EWOULDBLOCK. \n 1694 MSG_NOSIGNAL : Disables raising of SIGPIPE on stream sockets when the other end 1695 disappears. \n 1696 * @param[out] from A null pointer, or points to a sockaddr structure in which the sending address 1697 * is to be stored. The length and format of the address depend on the address family of the socket. 1698 * @param[out] fromlen Either a null pointer, if address is a null pointer, or a pointer to a socklen_t object 1699 * which on input specifies the length of the supplied sockaddr structure, and on output specifies the length of 1700 * the stored address. 1701 * 1702 * @return 1703 * Number of bytes received: Indicates a successful execution. \n 1704 * -1: Indicates a failure. 1705 * 1706 * @par Required Header File 1707 * sockets.h 1708 * @par Errors 1709 * @li The recvfrom() function fails if: 1710 * - <b> [EBADF] </b>: \n The socket argument is not a valid file descriptor. 1711 * - <b> [ECONNRESET] </b>: \n A connection was forcibly closed by a peer. 1712 * - <b> [EINVAL]</b>: \n Invalid input parameters. If mem, len is null or flags is less than zero, 1713 * lwIP returns failure. 1714 * - <b> [ENOBUFS] </b>: \n Insufficient resources were available in the system to perform the operation. 1715 * - <b> [ENOMEM] </b>: \n Insufficient memory was available to fulfil the request. 1716 * - <b> [ENOTCONN] </b>: \n A receive is attempted on a connection-mode socket that is not connected. 1717 * - <b> [EOPNOTSUPP] </b>: \n Some bit in the flags argument is unsupported for the socket type. 1718 * - <b> [EWOULDBLOCK] </b>: \n The socket's file descriptor is marked O_NONBLOCK or MSG_DONTWAIT flag is set 1719 * and no data is waiting to be received. 1720 * - <b> [EWOULDBLOCK] </b>: \n The socket was not marked with O_NONBLOCK, but set with option SO_RCVTIMEO, 1721 * and elapsed time is more than timeout value. 1722 1723 * @li The recvfrom() function may fail if: 1724 * - <b> [EIO]</b>: \n Internal errors. 1725 * @par Return value 1726 * Upon successful completion, recvfrom() shall return the length of the message in bytes. If no messages 1727 * are available to be received and the peer has performed an orderly shutdown, recvfrom() shall return 0. Otherwise, 1728 * the function shall return -1 and set errno to indicate the error. 1729 1730 * @par POSIX Conformance: 1731 * Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). The following are the exceptions 1732 * to conformance: 1733 - For UDP MSG_PEEK is not suported and data is discarded even if it is set. 1734 - MSG_OOB, MSG_WAITALL flags are not supported. 1735 1736 * @note 1737 * The behaviour of multiple concurrent reads on the same socket, is unspecified. 1738 - MSG_PEEK is not supported for UDP or RAW sockets. 1739 -UDP or RAW does not report memory allocation failure if memory allocation failed for received packet. 1740 - Instead of MSG_WAITALL, MSG_DONTWAIT is supported. 1741 - On TCP sockets, recvfrom() attempts to receive all the data from receive buffer if available. 1742 -TCP receive buffer is a list which holds the segment received from the peer. If the application calls the recv function 1743 to get the data, the function gets the first entry from the list and gives it back to application. 1744 This function does not recursively get entries from the list to fill the complete user buffer. 1745 -lwIP updates this receive buffer list when it gets the next expected segment. If there is any out of order segment 1746 - which is next to the received segment, lwIP merges the segments and puts that as one segment on 1747 - to the receive buffer list. 1748 - If the apps don't read the packet form the socket and the recv buffered packets up to MAX_MBOX_SIZE, 1749 the incoming packet may be discard by lwIP. 1750 - If the 'length' parameter is passed as zero, the stack will return -1 and errno will be set to EINVAL. 1751 - This behaviour is unspecified in POSIX specification, and a deviation from the LINUX implementation of recvfrom(), 1752 where it returns 0 when the buffer size is passed as zero. 1753 - MSG_TRUNC flag is not supported. 1754 - For TCP connection, when RST is received after FIN, this API will return 0 to indicate FIN, then return -1 1755 and set errno to ECONNRESET for RST. 1756 - For TCP connection, when data is received and RST is recevied together (push, ack, rst) flag is set then 1757 the data will be lost and RST will be processed. 1758 - This API is not thread-safe. 1759 * @par Related Topics 1760 * read() \n 1761 * recv() 1762 */ 1763 ssize_t lwip_recvfrom(int s, void *mem, size_t len, int flags, 1764 struct sockaddr *from, socklen_t *fromlen); 1765 1766 ssize_t lwip_recvmsg(int s, struct msghdr *message, int flags); 1767 1768 /* 1769 Func Name: lwip_send 1770 */ 1771 /** 1772 * @ingroup socket 1773 * @brief 1774 * This API initiates transmission of a message from the specified socket to its peer. 1775 * It sends a message only when the socket is connected. 1776 * 1777 * @param[in] s Specifies the socket file descriptor. 1778 * @param[in] dataptr Specifies a buffer containing message to send. 1779 * @param[in] size Specifies the length of the message to send. 1780 * @param[in] flags Indicates the flags of message transmission. 1781 * 1782 * @return 1783 * Number of bytes sent: Indicates a successful execution.\n 1784 * -1: Indicates failure. 1785 * 1786 * @par Errors 1787 * @li The send() function fails if: 1788 * - <b> [EADDINUSE] </b>: For PF_INET/SOCK_DGRAM socket without local port bond, when attempting to bind 1789 * to an ephemeral port, it was determined that all port numbers in the ephemeral port range are currently in use. 1790 * - <b> [EBADF] </b>: The socket argument is not a valid file descriptor. 1791 * - <b> [ECONNRESET] </b>: A connection was forcibly closed by a peer. 1792 * - <b> [EDESTADDRREQ] </b>: The socket is not connection-mode and does not have its peer address set. 1793 * - <b> [EINPROGRESS] </b>: For PF_INET/SOCK_STREAM, there was one send operation in progress, 1794 * and concurrent sending was not supported. 1795 * - <b> [EINVAL] </b>: Invalid argument passed, e.g. dataptr is NULL, size is zero. 1796 * - <b> [EMSGSIZE] </b>: The socket type requires that message be sent atomically, and the size of 1797 * the message to be sent made this impossible. For PF_PACKET/SOCK_RAW socket, it means the packet is larger 1798 * than the MTU of out network interface. For PF_INET/(SOCK_RAW,SOCK_DGRAM) socket, it means the packet is larger 1799 * than 65000 bytes. 1800 * - <b> [ENETDOWN] </b>: For PF_PACKET/SOCK_RAW socket, the binding network interface was down. 1801 * - <b> [ENOBUFS] </b>: Insufficient resources were available in the system to perform the operation. 1802 * - <b> [ENODEVADDR] </b>: For PF_PACKET/SOCK_RAW socket, the binding network interface does not exist. 1803 * - <b> [ENOMEM] </b>: Insufficient memory was available to fulfill the request. 1804 * - <b> [ENOTCONN] </b>: The socket is not connected. 1805 * - <b> [EOPNOTSUPP] </b>: Some bit in the flags argument is unsupported for the socket type. 1806 * - <b> [EPIPE] </b>: The socket is shut down for writing, or the socket is connection-mode and 1807 * is no longer connected. In the latter case, and if the socket is of type SOCK_STREAM. 1808 * - <b> [EWOULDBLOCK] </b>: The socket's file descriptor is marked O_NONBLOCK or MSG_DONWAIT flag is set and 1809 * the requested operation would block. 1810 * - <b> [EWOULDBLOCK] </b>: The socket was not marked with O_NONBLOCK, but set with option SO_SNDTIMEO, 1811 * and elapsed time is more than timeout value. 1812 1813 * @li The send() function may fail if: 1814 * - <b> [EIO] </b>: Internal errors. 1815 * @par POSIX Conformance: 1816 * Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). The following are 1817 * the exceptions to conformance: 1818 * - lwIP do not support half-close, if sending data on the socket that was shut down for writing, 1819 * it would failed and errno set to ENOTCONN, while it is EPIPE in POSIX. 1820 * - Return type is int instead of ssize_t 1821 * - If the socket is in connecting LwIP would return EINPROGRESS, which is ENOTCONN in POSIX. 1822 * 1823 * @note 1824 * - UDP and RAW connection can send only data of maximum length 65332. Sending more than data 1825 * will return -1 and errno set to EMSGSIZE. 1826 * - Only flag MSG_MORE and MSG_DONTWAIT is supported. Other flags, such as MSG_OOB/MSG_NOSIGNAL/MSG_EOR 1827 * are not supported.\n 1828 * 1829 * 1830 * @par Related Topics 1831 * write() 1832 * sendto() 1833 */ 1834 ssize_t lwip_send(int s, const void *dataptr, size_t size, int flags); 1835 1836 /** 1837 * @ingroup socket 1838 * @brief 1839 * This API initiates transmission of a message from the specified socket to its peer. 1840 * It sends a message only when the socket is connected. The sendmsg() call also allows 1841 * sending ancillary data (also known as control information). 1842 * 1843 * @param[in] s Specifies the socket file descriptor. 1844 * @param[in] message Specifies a buffer containing message to send. 1845 * @param[in] flags Indicates the types of message transmission. 1846 * 1847 * @return 1848 * Number of bytes sent: Indicates a successful execution.\n 1849 * -1: Indicates failure. 1850 * 1851 * @par Errors 1852 * @li The sendmsg() function fails if: 1853 * - <b> [EADDINUSE] </b>: For PF_INET/SOCK_DGRAM socket without local port bond, when attempting to 1854 * bind to an ephemeral port, it was determined that all port numbers in the ephemeral port range are currently in use. 1855 * - <b> [EBADF] </b>: The socket argument is not a valid file descriptor. 1856 * - <b> [ECONNRESET] </b>: A connection was forcibly closed by a peer. 1857 * - <b> [EDESTADDRREQ] </b>: The socket is not connection-mode and does not have its peer address set. 1858 * - <b> [EINPROGRESS] </b>: For PF_INET/SOCK_STREAM, there was one send operation in progress, 1859 * and concurrent sending was not supported. 1860 * - <b> [EINVAL] </b>: Invalid argument passed, e.g. dataptr is NULL, size is zero. 1861 * - <b> [EMSGSIZE] </b>: The socket type requires that message be sent atomically, and the size of the message 1862 * to be sent made this impossible. For PF_PACKET/SOCK_RAW socket, it means the packet is larger than the MTU of 1863 * out network interface. For PF_INET/(SOCK_RAW,SOCK_DGRAM) socket, it means the packet is larger than 65000 bytes. 1864 * - <b> [ENETDOWN] </b>: For PF_PACKET/SOCK_RAW socket, the binding network interface was down. 1865 * - <b> [ENOBUFS] </b>: Insufficient resources were available in the system to perform the operation. 1866 * - <b> [ENODEVADDR] </b>: For PF_PACKET/SOCK_RAW socket, the binding network interface does not exist. 1867 * - <b> [ENOMEM] </b>: Insufficient memory was available to fulfill the request. 1868 * - <b> [ENOTCONN] </b>: The socket is not connected. 1869 * - <b> [EOPNOTSUPP] </b>: Some bit in the flags argument is unsupported for the socket type. 1870 * - <b> [EPIPE] </b>: The socket is shut down for writing, or the socket is connection-mode 1871 * and is no longer connected. In the latter case, and if the socket is of type SOCK_STREAM. 1872 * - <b> [EWOULDBLOCK] </b>: The socket's file descriptor is marked O_NONBLOCK 1873 * or MSG_DONWAIT flag is set and the requested operation would block. 1874 * - <b> [EWOULDBLOCK] </b>: The socket was not marked with O_NONBLOCK, 1875 * but set with option SO_SNDTIMEO, and elapsed time is more than timeout value. 1876 1877 * @li The sendmsg() function may fail if: 1878 * - <b> [EIO] </b>: Internal errors. 1879 * @par POSIX Conformance: 1880 * Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). 1881 * The following are the exceptions to conformance: 1882 * - lwIP do not support half-close, if sending data on the socket that was shut down 1883 * for writing, it would failed and errno set to ENOTCONN, while it is EPIPE in POSIX. 1884 * - Return type is int instead of ssize_t 1885 * - If the socket is in connecting LwIP would return EINPROGRESS, which is ENOTCONN in POSIX. 1886 * 1887 * @note 1888 * - UDP and RAW connection can send only data of maximum length 65332. Sending more than data 1889 * will return -1 and errno set to EMSGSIZE. 1890 * - Only flag MSG_MORE and MSG_DONTWAIT is supported. Other flags, such as 1891 * MSG_OOB/MSG_NOSIGNAL/MSG_EOR are not supported.\n 1892 * 1893 * 1894 * @par Related Topics 1895 * write() 1896 * sendto() 1897 */ 1898 ssize_t lwip_sendmsg(int s, const struct msghdr *message, int flags); 1899 1900 /* 1901 Func Name: lwip_sendto 1902 */ 1903 /** 1904 * @ingroup socket 1905 * @brief 1906 * This API is used to send messages from a connection-oriented and connectionless sockets. 1907 * If the socket is in the connectionless mode, the message is sent to the address specified by the 'to' parameter. 1908 * If the socket is in the connection mode, the destination address in the 'to' parameter is ignored. 1909 * 1910 * @param[in] s Specifies a socket file descriptor. 1911 * @param[in] dataptr Specifies a buffer containing the message to send. 1912 * @param[in] size Specifies the length of the message to send. 1913 * @param[in] flags Indicates the flags of message transmission. 1914 * @param[in] to Specifies a pointer to the sockaddr structure that contains the destination address. 1915 * @param[in] tolen Specifies the size of the 'to' structure. 1916 * 1917 * @return 1918 * Number of bytes sent: Indicates a successful execution. \n 1919 * -1: Indicates a failure. 1920 * @par Errors 1921 * @li The sendto() function fails if: 1922 * - <b> [EACCES] </b>: For PF_INET/(SOCK_RAW,SOCK_DGRAM) socket, the destination address is broadcast 1923 * but SO_BROADCAST option was not enabled. 1924 * - <b> [EADDINUSE] </b>: For PF_INET/SOCK_DGRAM socket without local port bond, when attempting to bind 1925 * to an ephemeral port, it was determined that all port numbers in the ephemeral port range are currently in use. 1926 * - <b> [EAFNOSUPPORT] </b>: Addresses in the specified address family cannot be used with this socket. 1927 * - <b> [EBADF] </b>: The socket argument is not a valid file descriptor. 1928 * - <b> [ECONNRESET] </b>: A connection was forcibly closed by a peer. 1929 * - <b> [EDESTADDRREQ] </b>: The socket is not connection-mode and does not have its peer address set, 1930 * and no destination address was specified. 1931 * - <b> [EINPROGRESS] </b>: For PF_INET/SOCK_STREAM, there was one send operation in progress, 1932 * and concurrent sending was not supported. 1933 * - <b> [EINVAL] </b>: Invalid argument passed. For example, dataptr is NULL, size is zero. 1934 * - <b> [EMSGSIZE] </b>: The socket type requires that message be sent atomically, and the size of 1935 * the message to be sent made this impossible. For PF_PACKET/SOCK_RAW socket, it means the packet is larger 1936 * than the MTU of out network interface. For PF_INET/(SOCK_RAW,SOCK_DGRAM) socket, it means the packet is larger 1937 * than 65000 bytes. 1938 * - <b> [ENETDOWN] </b>: For PF_PACKET/SOCK_RAW socket, the out network interface was down. 1939 * - <b> [ENETUNREACH] </b>: No route to the destination is present. 1940 * - <b> [ENOBUFS] </b>: Insufficient resources were available in the system to perform the operation. 1941 * - <b> [ENOMEM] </b>: Insufficient memory was available to fulfill the request. 1942 * - <b> [ENOTCONN] </b>: The socket is not connected. 1943 * - <b> [ENXIO] </b>: For PF_PACKET/SOCK_RAW socket, the given network interface does not exist. 1944 * - <b> [EOPNOTSUPP] </b>: Some bit in the flags argument is unsupported for the socket type. 1945 * - <b> [EPIPE] </b>: The socket is shut down for writing, or the socket is connection-mode and 1946 * is no longer connected. In the latter case, and if the socket is of type SOCK_STREAM. 1947 * - <b> [EWOULDBLOCK] </b>: The socket's file descriptor is marked O_NONBLOCK or MSG_DONTWAIT flag is set 1948 * and the requested operation would block. 1949 * - <b> [EWOULDBLOCK] </b>: The socket was not marked with O_NONBLOCK, but set with option SO_SNDTIMEO, 1950 * and elapsed time is more than timeout value. 1951 1952 * @li The sendto() function may fail if: 1953 * - <b> [EIO] </b>: Internal error. 1954 * @par POSIX Conformance: 1955 Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). The following are the exceptions 1956 to conformance: 1957 - For UDP/RAW socket, sendto() override peer address set in connect by address provided in sendto, and does not 1958 return failure with EISCONN. 1959 - TCP ignore destination address provided in sendto(), and use connection set up by connect() 1960 - MSG_EOR, MSG_OOB, MSG_NOSIGNAL, are not suported, lwip fails with errnor set to EOPNOTSUPP. 1961 * - LwIP does not support half-close, if sending data on the socket that was shut down for writing, it would failed 1962 * and errno set to ENOTCONN, while it is EPIPE in POSIX. 1963 * - For PF_PACKET SOCK_RAW socket, if given network interface index does not exist, lwIP return failure with errno 1964 ENXIO. 1965 * - If the socket is in connecting LwIP would return EINPROGRESS, which is ENOTCONN in POSIX. 1966 * @note 1967 * - AF_INET/AF_INET6 UDP and RAW connection can send only data of maximum length 65332. Sending more than data 1968 * will return failure with return value -1 and errno set to EMSGSIZE. 1969 * - Only flag MSG_MORE and MSG_DONTWAIT is supported, other flags, such as MSG_OOB/MSG_NOSIGNAL/MSG_EOR is not supported 1970 * 1971 * @par Related Topics 1972 * write() \n 1973 * send() 1974 */ 1975 ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags, 1976 const struct sockaddr *to, socklen_t tolen); 1977 1978 /* 1979 Func Name: lwip_socket 1980 */ 1981 /** 1982 * @ingroup socket 1983 * @brief 1984 * This API is used to allocate a socket. 1985 * It creates an endpoint for communication and returns a file descriptor. 1986 * 1987 * @param[in] domain Specifies a protocol family. 1988 * @param[in] type Specifies the socket type. [SOCK_RAW|SOCK_DGRAM,SOCK_STREAM] 1989 * @param[in] protocol Specifies the protocol to be used with the socket. 1990 * 1991 * @return 1992 * Valid socket file descriptor: On success. \n 1993 * -1: On failure. 1994 * @par Errors 1995 * @li The socket() function fails if: 1996 * - <b>[EAFNOSUPPORT] </b>: \n The implementation does not support the specified address family. 1997 * - <b>[EINVAL] </b>: \n Invalid type or invalid flags in type. 1998 * - <b>[ENFILE] </b>: \n The maximum number of sockets in the system are already open. 1999 * - <b>[ENOBUFS] </b>: \n Insufficient resources were available in the system to perform the operation. 2000 * - <b>[EPROTONOSUPPORT] </b>: \n The specified protocol is not supported within this domain & type. 2001 * - <b>[ESOCKTNOSUPPORT] </b>: \n The socket type is not supported within this domain. 2002 * @par POSIX Conformance: 2003 Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). The following are the exceptions 2004 to conformance: 2005 - socket() does not validate domain. It assumes it to be AF_INET(PF_INET) if not PF_PACKET. As per POSIX it should 2006 return failure with errno [EAFNOSUPPORT], but it does not return that error. 2007 - For socket type not recognised by socket it returns failure with errno ESOCKTNOSUPPORT instead of EPROTOTYPE. 2008 * @note 2009 * - PF_PACKET is supported only for SOCK_RAW. 2010 * - For AF_INET socket SOCK_RAW | SOCK_DGRAM | SOCK_STREAM types are supported. 2011 * - For AF_PACKET, only the SOCK_RAW type is supported. 2012 * - For AF_INET6 socket SOCK_RAW | SOCK_DGRAM | SOCK_STREAM types are supported. 2013 */ 2014 int lwip_socket(int domain, int type, int protocol); 2015 2016 /* 2017 Func Name: lwip_write 2018 */ 2019 /** 2020 * @ingroup socket 2021 * @brief 2022 * This API is used to send data on connection-oriented sockets. 2023 * 2024 * @param[in] s Specifies a socket file descriptor. 2025 * @param[in] dataptr Specifies a buffer containing the message to send. 2026 * @param[in] size Specifies the length of the message to send. 2027 * 2028 * @return 2029 * Number of bytes sent: Indicates success. \n 2030 * -1: Indicates failure. 2031 * 2032 * @par Errors 2033 * @li The write() function shall fail if: 2034 * - <b> [EWOULDBLOCK] </b>: The socket's file descriptor is marked O_NONBLOCK or MSG_DONWAIT flag is set and 2035 * the requested operation would block. 2036 * - <b> [EWOULDBLOCK] </b>: The socket was not marked with O_NONBLOCK, but set with option SO_SNDTIMEO, 2037 * and elapsed time is more than timeout value. 2038 * - <b> [EADDINUSE] </b>: For PF_INET/SOCK_DGRAM socket without local port bond, when attempting to bind 2039 * to an ephemeral port, it was determined that all port numbers in the ephemeral port range are currently in use. 2040 * - <b> [EBADF] </b>: The socket argument is not a valid file descriptor. 2041 * - <b> [ECONNRESET] </b>: A connection was forcibly closed by a peer. 2042 * - <b> [EDESTADDRREQ] </b>: The socket is not connection-mode and does not have its peer address set. 2043 * - <b> [EINPROGRESS] </b>: For PF_INET/SOCK_STREAM, there was one send operation in progress, 2044 * and concurrent sending was not supported. 2045 * - <b> [EINVAL] </b>: Invalid argument passed. For example, dataptr is NULL or size is zero. 2046 * - <b> [EMSGSIZE] </b>: The socket type requires that message be sent atomically, and the size of the message 2047 * to be sent made this impossible. For PF_PACKET/SOCK_RAW socket, it means the packet is larger than the MTU 2048 * of out network interface. For PF_INET/(SOCK_RAW,SOCK_DGRAM) socket, 2049 * it means the packet is larger than 65000 bytes. 2050 * - <b> [ENETDOWN] </b>: For PF_PACKET/SOCK_RAW socket, the binding network interface was down. 2051 * - <b> [ENOBUFS] </b>: Insufficient resources were available in the system to perform the operation. 2052 * - <b> [ENOMEM] </b>: Insufficient memory was available to fulfill the request. 2053 * - <b> [ENODEVADDR] </b>: For PF_PACKET/SOCK_RAW socket, the binding network interface does not exist. 2054 * - <b> [ENOTCONN] </b>: The socket is not connected. 2055 2056 * @li The write() function may fail if: 2057 * - <b> [EIO] </b>: Internal errors. 2058 2059 * @par POSIX Conformance: 2060 * Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). The following are the exceptions 2061 * to conformance: 2062 * - Return type is int instead of ssize_t 2063 * - lwIP sets EWOULDBLOCK instead of EAGAIN, wherever EAGAIN is set to errno. 2064 * @note 2065 * - For sockets not marked with O_NONBLOCK, and socket set with option SP_SENDTIMEO, 2066 * and elapsed time is more than timeout value, lwIP shall fail with errno EAGAIN. 2067 * @par Related Topics 2068 * send() \n 2069 * sendto() 2070 */ 2071 ssize_t lwip_write(int s, const void *dataptr, size_t size); 2072 2073 /** 2074 * @ingroup socket 2075 * @brief 2076 * The writev() function writes iovcnt buffers of data described by iov to the file associated with the file 2077 * descriptors. 2078 * 2079 * @param[in] s Specifies a file descriptor. 2080 * @param[in] iov Indicates buffers of data. 2081 * @param[in] iovcnt Indicates the number of buffers. 2082 * 2083 * @return 2084 * Number of bytes sent: Indicates success. \n 2085 * -1: Indicates failure. 2086 * 2087 * @par Errors 2088 * @li The writev() function shall fail if: 2089 * - <b> [EWOULDBLOCK] </b>: The socket's file descriptor is marked O_NONBLOCK 2090 * or MSG_DONWAIT flag is set and the requested operation would block. 2091 * - <b> [EWOULDBLOCK] </b>: The socket was not marked with O_NONBLOCK, 2092 * but set with option SO_SNDTIMEO, and elapsed time is more than timeout value. 2093 * - <b> [EADDINUSE] </b>: For PF_INET/SOCK_DGRAM socket without local port bond, 2094 * when attempting to bind to an ephemeral port, it was determined that all port numbers in the ephemeral port range 2095 * are currently in use. 2096 * - <b> [EBADF] </b>: The socket argument is not a valid file descriptor. 2097 * - <b> [ECONNRESET] </b>: A connection was forcibly closed by a peer. 2098 * - <b> [EDESTADDRREQ] </b>: The socket is not connection-mode and does not have its peer address set. 2099 * - <b> [EINPROGRESS] </b>: For PF_INET/SOCK_STREAM, there was one send operation 2100 * in progress, and concurrent sending was not supported. 2101 * - <b> [EINVAL] </b>: Invalid argument passed. For example, dataptr is NULL or size is zero. 2102 * - <b> [EMSGSIZE] </b>: The socket type requires that message be sent atomically, 2103 * and the size of the message to be sent made this impossible. For PF_PACKET/SOCK_RAW socket, 2104 * it means the packet is larger than the MTU of out network interface. 2105 * For PF_INET/(SOCK_RAW,SOCK_DGRAM) socket, it means the packet is larger than 65000 bytes. 2106 * - <b> [ENETDOWN] </b>: For PF_PACKET/SOCK_RAW socket, the binding network interface was down. 2107 * - <b> [ENOBUFS] </b>: Insufficient resources were available in the system to perform the operation. 2108 * - <b> [ENOMEM] </b>: Insufficient memory was available to fulfil the request. 2109 * - <b> [ENODEVADDR] </b>: For PF_PACKET/SOCK_RAW socket, the binding network interface does not exist. 2110 * - <b> [ENOTCONN] </b>: The socket is not connected. 2111 2112 * @li The writev() function may fail if: 2113 * - <b> [EIO] </b>: Internal errors. 2114 2115 * @par POSIX Conformance: 2116 * Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). 2117 * The following are the exceptions to conformance: 2118 * - Return type is int instead of ssize_t 2119 * - lwIP sets EWOULDBLOCK instead of EAGAIN, wherever EAGAIN is set to errno. 2120 * @note 2121 * - For sockets not marked with O_NONBLOCK, 2122 * and socket set with option SP_SENDTIMEO, and elapsed time is more than timeout value, 2123 * lwIP shall fail with errno EAGAIN. 2124 * @par Related Topics 2125 * send() \n 2126 * sendto() 2127 */ 2128 ssize_t lwip_writev(int s, const struct iovec *iov, int iovcnt); 2129 #if LWIP_SOCKET_SELECT 2130 /* 2131 Func Name: lwip_select 2132 */ 2133 /** 2134 * @ingroup socket 2135 * @brief 2136 * 2137 select() allows a program to monitor multiple file 2138 descriptors, waiting until one or more of the file descriptors become 2139 "ready" for some class of I/O operation (input possible). A 2140 file descriptor is considered ready if it is possible to perform a 2141 corresponding I/O operation (read() without blocking, or a 2142 sufficiently small write()). 2143 2144 select() can monitor only file descriptors numbers that are less than 2145 FD_SETSIZE. 2146 2147 select() uses a timeout that is a struct timeval (with seconds 2148 and microseconds). 2149 Three independent sets of file descriptors are watched. The file 2150 descriptors listed in readfds will be watched to see if characters 2151 become available for reading (more precisely, to see if a read will 2152 not block; in particular, a file descriptor is also ready on end-of- 2153 file). The file descriptors in writefds will be watched to see if 2154 space is available for write (though a large write may still block). 2155 The file descriptors in exceptfds will be watched for exceptional 2156 conditions. 2157 On exit, each of the file descriptor sets is modified in place to 2158 indicate which file descriptors actually changed status. (Thus, if 2159 using select() within a loop, the sets must be reinitialized before 2160 each call.) 2161 2162 Each of the three file descriptor sets may be specified as NULL if no 2163 file descriptors are to be watched for the corresponding class of 2164 events. 2165 2166 Four macros are provided to manipulate the sets. FD_ZERO() clears a 2167 set. FD_SET() and FD_CLR() respectively add and remove a given file 2168 descriptor from a set. FD_ISSET() tests to see if a file descriptor 2169 is part of the set; this is useful after select() returns. 2170 2171 nfds should be set to the highest-numbered file descriptor in any of 2172 the three sets, plus 1. The indicated file descriptors in each set 2173 are checked, up to this limit 2174 2175 2176 The timeout argument specifies the interval that select() should 2177 block waiting for a file descriptor to become ready. The call will 2178 block until either: 2179 - a file descriptor becomes ready; 2180 - the timeout expires. 2181 2182 Note that the timeout interval will be rounded up to the system clock 2183 granularity, and kernel scheduling delays mean that the blocking 2184 interval may overrun by a small amount. If both fields of the 2185 timeval structure are zero, then select() returns immediately. (This 2186 is useful for polling.) If timeout is NULL (no timeout), select() 2187 can block indefinitely. 2188 2189 * @param[in] maxfdp1 Specifies a range of file descriptors. 2190 * @param[in] readfds Specifies a pointer to struct fd_set, and specifies the descriptor to check 2191 * for being ready to read. 2192 * @param[in] writefds Specifies a pointer to struct fd_set, and specifies the descriptor to check 2193 * for being ready to write. 2194 * @param[in] exceptfds Specifies a pointer to struct fd_set, and specifies the descriptor to check 2195 * for pending error conditions. 2196 * @param[in] timeout Specifies a pointer to struct timeval, for timeout application. 2197 * 2198 * @return 2199 * Socket file descriptor: On success \n 2200 * -1: On failure \n 2201 * @par POSIX Conformance: 2202 Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). The following are 2203 the exceptions to conformance: 2204 - select() does not validate if nfds argument, does not check if argument is less than zero or greater than FD_SETSIZE. 2205 - As per POSIX, implementations may place limitations on the maximum timeout interval supported. 2206 All implementations shall support a maximum timeout interval of at least 31 days, but lwIP limits value 2207 until any overflow happens, timer with very high value might result in unspecified behavior. 2208 2209 * @par Errors 2210 * The select() function shall fail if: 2211 * - <b>[EBADF] </b>: \n One or more of the file descriptor sets specified a file descriptor 2212 * that is not a valid open file descriptor. 2213 * - <b>[EINVAL] </b>: \n An invalid timeout interval was specified. \n 2214 * - <b>[ENOMEM] </b>: \n Insufficient resources or memory, memory allocation failed. 2215 2216 * @note 2217 - The select() API does not update the timeout argument to indicate how much time was left. 2218 - FD_SETSIZE is compile time configurable in lwIP, and application must ensure it does not violate this boundary, 2219 lwIP does not validate this at runtime. 2220 2221 * @par Multithreaded Application 2222 * If a file descriptor being monitored by select() is closed in another 2223 * thread, the result is unspecified. lwIP may return without setting any fdset. 2224 * On some UNIX systems, select() unblocks and returns, with an indication that the file descriptor is 2225 * ready (a subsequent I/O operation will likely fail with an error, 2226 * unless another the file descriptor reopened between the time select() 2227 * returned and the I/O operations was performed). On Linux (and some 2228 * other systems), closing the file descriptor in another thread has no 2229 * effect on select(). In summary, any application that relies on a 2230 * particular behaviour in this scenario must be considered buggy. 2231 */ 2232 int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, 2233 struct timeval *timeout); 2234 #endif 2235 #if LWIP_SOCKET_POLL 2236 #if LWIP_EXT_POLL_SUPPORT 2237 /* 2238 * Func Name: lwip_poll 2239 * */ 2240 /** 2241 * @ingroup socket 2242 * @brief 2243 * This API is used to poll on multiple file descriptors, waiting until one or more of the file descriptors 2244 * become "ready" for some of I/O operations. 2245 * @param[in] sockfd socket file descriptor 2246 * @param[in] wait Indicates poll table struct include events provided by the user. 2247 * @return 2248 * Socket file descriptor: On success \n 2249 * -1: On failure \n 2250 */ 2251 int lwip_poll(int sockfd, poll_table *wait); 2252 #else 2253 int lwip_poll(struct pollfd *fds, nfds_t nfds, int timeout); 2254 #endif /* LWIP_EXT_POLL_SUPPORT */ 2255 #endif 2256 2257 /* 2258 Func Name: lwip_ioctl 2259 */ 2260 /** 2261 * @ingroup socket 2262 * @brief 2263 This function manipulates the underlying device parameters of 2264 special files. In particular, many operating characteristics of 2265 character special files (for example, terminals) may be controlled with 2266 ioctl() requests. The argument fd must be an open file descriptor. 2267 2268 The second argument is a device-dependent request code. 2269 2270 An ioctl() request has encoded in it whether the argument is an input 2271 parameter or output parameter, and the size of the argument argp in 2272 bytes. 2273 2274 * @param[in] s Specifies an open socket file descriptor. 2275 * @param[in] cmd Specifies a device-dependent request code. 2276 * @param[in] argp Specifies additional information, if required. 2277 * 2278 * 2279 * @return 2280 * Usually, on success zero is returned. A few ioctl() requests use the 2281 * return value as an output parameter and return a nonnegative value on 2282 * success. On error, -1 is returned, and errno is set appropriately. 2283 * 2284 * @par Errors 2285 * @li The ioctl() function shall fail if: 2286 * - <b> [EBADF] </b> : The fd argument is not a valid open file descriptor. 2287 * - <b> [EINVAL] </b> : The request or arg argument is not valid for this device. 2288 * - <b> [ENOMEM] </b> : If any resource allocation fails, ENOMEM is set as errno. 2289 * - <b> [ENODEV] </b> : If no device found, ENODEV is set as errno. 2290 * - <b> [EPERM] </b> : If specified device is loopback i.e. "lo", EPERM is set as errno. 2291 * @li The ioctl() function may fail if: 2292 * - <b> [EAFNOSUPPORT] </b>: If socket created with PF_PACKET, SOCK_RAW is called with SIOCADDRT. 2293 * - <b> [EIO] </b>: If socket failed to set/get ethtool settings, called with SIOCETHTOOL. 2294 * - <b> [ENOSYS] </b>: If specified option is not supported/unimplemented, then errno is set as ENOSYS. 2295 * @note 2296 * - Linux API supports variable argument support. The lwIP API supports only one void * as the 2297 * third argument. \n 2298 * - This API supports the following options: \n 2299 * - SIOCADDRT: Set IF gateway, soft-route is not support by lwIP yet. \n 2300 * - SIOCGIFADDR: Get ifnet address.\n 2301 * - SIOCGIFFLAGS: Get ifnet flags.\n 2302 * - SIOCSIFFLAGS: Set ifnet flags.\n 2303 * - IFF_UP: Interface is up.\n 2304 * - IFF_BROADCAST: Broadcast address valid.\n 2305 * - IFF_LOOPBACK: Is a loopback net.\n 2306 * - IFF_POINTOPOINT: Is a point-to-point link.\n 2307 * - IFF_DRV_RUNNING: Resources allocated.\n 2308 * - IFF_NOARP: No address resolution protocol.\n 2309 * - IFF_MULTICAST: Supports multicast.\n 2310 * - IFF_DYNAMIC: Dialup device with changing addresses.\n 2311 * - IFF_DYNAMIC_S: Dialup device with changing addresses.\n 2312 * 2313 * - This API also supports the following options for only AF_INET sockets: \n 2314 * - SIOCGIFADDR: Get ifnet address.\n 2315 * - SIOCGIFNETMASK: Get net addr mask.\n 2316 * - SIOCSIFNETMASK : Set net addr mask.\n 2317 * - This API also supports the following options for AF_INET & AF_INET6 sockets: \n 2318 * - SIOCSIFADDR: Set ifinet or ifnet6 address. \n 2319 * - SIOCDIFADDR: Delete ifinet or ifnet6 address. It does not allow removal of IPv6 link local address.\n 2320 * - SIOCSIFHWADDR: Set IF mac_address.\n 2321 * - SIOCGIFHWADDR: Get IF mac_address\n 2322 * - SIOCGIFNAME: Get IF name.\n 2323 * - SIOCSIFNAME: Set IF name.\n 2324 * - SIOCGIFMTU: Get IF mtu size.\n 2325 * - SIOCSIFMTU: Set IF mtu size.\n 2326 * - SIOCGIFINDEX: Get IF index.\n 2327 * - SIOCGIFCONF: Get ifnet config. \n 2328 * - SIOCETHTOOL: Detect eth link status. \n 2329 * - FIONBIO: Set/clear non-blocking i/o.\n 2330 * - FIONREAD:get the size of buffer.\n 2331 * - For SIOCSIFNAME, the new name must be consisted by letters and numbers, and the letters must be in front of numbers. 2332 * The number range is from 0 to 255.\n 2333 * - For FIONREAD option, argp should point to an application variable of type signed int. 2334 * FIONREAD is supported if LWIP_SO_RCVBUF is enabled. \n 2335 * - For PF_PACKET sockets SIOCADDRT option is not supported. The options supported are: 2336 * - FIONBIO 2337 * - SIOCGIFADDR 2338 * - SIOCSIFADDR 2339 * - SIOCGIFNETMASK 2340 * - SIOCSIFNETMASK 2341 * - SIOCSIFHWADDR 2342 * - SIOCGIFHWADDR 2343 * - SIOCGIFFLAGS 2344 * - SIOCSIFFLAGS 2345 * - SIOCGIFNAME 2346 * - SIOCSIFNAME 2347 * - SIOCGIFINDEX 2348 * - SIOCGIFCONF 2349 * - For SIOCSIFADDR/SIOSIFNETMASK option, the gateway address is reset if the changed\n 2350 * netif was the default netif and the gateway was unreachable after changing.\n 2351 * Also duplicate network is forbidden.\n 2352 * - For SIOCADDRT, only gateway setting is supported(flags in "struct rtentry" must be RTF_GATEWAY).\n 2353 * Note- SIOCGIFADDR is not supported for IPv6 addresses, developer should use getifaddrs() 2354 * 2355 */ 2356 int lwip_ioctl(int s, long cmd, void *argp); 2357 2358 /* 2359 Func Name: lwip_fcntl 2360 */ 2361 /** 2362 * @ingroup socket 2363 * @brief 2364 * The fcntl() function performs the operations described below on open files. The fd argument is a file descriptor. 2365 * @li The available values for cmd are as follows: 2366 * - F_GETFL: Get the file status flags and file access mode for the file description associated with file descriptor. 2367 * The flags returned may include non-standard file status flags which the application did not set, provided 2368 * that these additional flags do not alter the behavior of a conforming application. 2369 * - F_SETFL: val the file status flags for the file description associated with fildes from the corresponding bits 2370 * in the third argument, val, taken as type int. Bits corresponding to the file access mode 2371 * and the file creation flags, that are set in arg shall be ignored. 2372 * If any bits in val other than those mentioned here are changed by the application, 2373 * the result is unspecified. If fildes does not support non-blocking operations, it is unspecified 2374 * whether the O_NONBLOCK flag will be ignored. 2375 * 2376 2377 * @param[in] s Indicates the socket file descriptor. 2378 * @param[in] cmd Indicates a command to select an operation [F_GETFL, F_SETFL]. 2379 * @param[in] val Indicates an additional flag, to set non-blocking. 2380 * 2381 * @return 2382 * Upon successful completion, the value returned depends on cmd as follows: 2383 * @li F_GETFL: Value of file status flags and access modes. The return value is not negative. 2384 * @li F_SETFL: Value other than -1. 2385 * 2386 * @par Errors 2387 * @li The fcntl() function shall fail if: 2388 * - <b> [EBADF] </b> : \n The field argument is not a valid opened file descriptor. 2389 * - <b> [EINVAL] </b> : \n The cmd argument is invalid, or cmd not supported by implementation, 2390 or if val is set to any other value other than O_NONBLOCK. Only F_GETFL and F_SETFL are supported by lwIP. 2391 * @par POSIX Conformance: 2392 Implementation deviates from POSIX.1-2008 (IEEE Std 1003.1-2008, 2016 Edition). The following are the exceptions 2393 to conformance: 2394 - Function prototype does not support variable arguments like POSIX or Linux fcntl API. 2395 - The arg values to F_GETFL, and F_SETFL all represent flag values to allow for future growth. 2396 Applications using these functions should do a read-modify-write operation on them, rather than assuming that 2397 only the values defined by POSIX.1-2008 are valid. It is a common error to forget this, particularly in the case of 2398 F_SETFD. Some implementations set additional file status flags to advise the application of default behavior, 2399 even though the application did not request these flags. 2400 * @note 2401 2402 * - Only F_GETFL & F_SETFL commands are supported. For F_SETFL, only O_NONBLOCK is supported for val. 2403 * - PF_PACKET sockets supports the F_SETFL and F_GETFL option. 2404 */ 2405 int lwip_fcntl(int s, int cmd, int val); 2406 const char *lwip_inet_ntop(int af, const void *src, char *dst, socklen_t size); 2407 int lwip_inet_pton(int af, const char *src, void *dst); 2408 2409 /* internal function. */ 2410 /* Call this function to intialise global socket resources 2411 */ 2412 int sock_init(void); 2413 2414 /** 2415 * @ingroup socket 2416 * @brief 2417 * This API is used to get TCP or UDP connection information. 2418 2419 * @param[in] s Indicates a socket file descriptor. 2420 * @param[out] conninfo Connection information details of given socket. 2421 * 2422 * 2423 * @return 2424 * 0: On success \n 2425 * Negative value: On failure 2426 2427 * @par Errors 2428 * \li The lwip_get_conn_info() function fails if: 2429 * - <b> [ERR_CLSD] </b>: The Connections are not valid TCP or UDP connections. 2430 * - <b> [EIO] </b>: Internal Error , validation issue. 2431 * - <b> [EOPNOTSUPP] </b>: Not a UDP/TCP connection or TCP connection in listen state. 2432 * - <b> [ERR_CONN] </b>: For unconnected TCP connections. 2433 * 2434 * @note 2435 * - This function called to get TCP or UDP connection information. 2436 * - The void pointer is of type tcpip_conn. 2437 * - This API does not support getting connection information of the TCP socket in LISTEN state.\n 2438 */ 2439 int lwip_get_conn_info(int s, void *conninfo); 2440 2441 int get_unused_socket_num(void); 2442 2443 #if LWIP_COMPAT_SOCKETS 2444 #if LWIP_COMPAT_SOCKETS != 2 2445 /** @ingroup socket */ 2446 #define accept(s,addr,addrlen) lwip_accept(s,addr,addrlen) 2447 /** @ingroup socket */ 2448 #define bind(s,name,namelen) lwip_bind(s,name,namelen) 2449 /** @ingroup socket */ 2450 #define shutdown(s,how) lwip_shutdown(s,how) 2451 /** @ingroup socket */ 2452 #define getpeername(s,name,namelen) lwip_getpeername(s,name,namelen) 2453 /** @ingroup socket */ 2454 #define getsockname(s,name,namelen) lwip_getsockname(s,name,namelen) 2455 /** @ingroup socket */ 2456 #define setsockopt(s,level,optname,opval,optlen) lwip_setsockopt(s,level,optname,opval,optlen) 2457 /** @ingroup socket */ 2458 #define getsockopt(s,level,optname,opval,optlen) lwip_getsockopt(s,level,optname,opval,optlen) 2459 /** @ingroup socket */ 2460 #define closesocket(s) lwip_close(s) 2461 /** @ingroup socket */ 2462 #define connect(s,name,namelen) lwip_connect(s,name,namelen) 2463 /** @ingroup socket */ 2464 #define listen(s,backlog) lwip_listen(s,backlog) 2465 /** @ingroup socket */ 2466 #define recv(s,mem,len,flags) lwip_recv(s,mem,len,flags) 2467 /** @ingroup socket */ 2468 #define recvmsg(s,message,flags) lwip_recvmsg(s,message,flags) 2469 /** @ingroup socket */ 2470 #define recvfrom(s,mem,len,flags,from,fromlen) lwip_recvfrom(s,mem,len,flags,from,fromlen) 2471 /** @ingroup socket */ 2472 #define send(s,dataptr,size,flags) lwip_send(s,dataptr,size,flags) 2473 /** @ingroup socket */ 2474 #define sendmsg(s,message,flags) lwip_sendmsg(s,message,flags) 2475 /** @ingroup socket */ 2476 #define sendto(s,dataptr,size,flags,to,tolen) lwip_sendto(s,dataptr,size,flags,to,tolen) 2477 /** @ingroup socket */ 2478 #define socket(domain,type,protocol) lwip_socket(domain,type,protocol) 2479 #if LWIP_SOCKET_SELECT 2480 /** @ingroup socket */ 2481 #define select(maxfdp1,readset,writeset,exceptset,timeout) lwip_select(maxfdp1,readset,writeset,exceptset,timeout) 2482 #endif 2483 #if LWIP_SOCKET_POLL && !LWIP_EXT_POLL_SUPPORT 2484 /** @ingroup socket */ 2485 #define poll(fds,nfds,timeout) lwip_poll(fds,nfds,timeout) 2486 #endif 2487 /** @ingroup socket */ 2488 #define ioctlsocket(s,cmd,argp) lwip_ioctl(s,cmd,argp) 2489 /** @ingroup socket */ 2490 #define inet_ntop(af,src,dst,size) lwip_inet_ntop(af,src,dst,size) 2491 /** @ingroup socket */ 2492 #define inet_pton(af,src,dst) lwip_inet_pton(af,src,dst) 2493 2494 #if LWIP_POSIX_SOCKETS_IO_NAMES 2495 /** @ingroup socket */ 2496 #define read(s,mem,len) lwip_read(s,mem,len) 2497 /** @ingroup socket */ 2498 #define readv(s,iov,iovcnt) lwip_readv(s,iov,iovcnt) 2499 /** @ingroup socket */ 2500 #define write(s,dataptr,len) lwip_write(s,dataptr,len) 2501 /** @ingroup socket */ 2502 #define writev(s,iov,iovcnt) lwip_writev(s,iov,iovcnt) 2503 /** @ingroup socket */ 2504 #define close(s) lwip_close(s) 2505 /** @ingroup socket */ 2506 #define fcntl(s,cmd,val) lwip_fcntl(s,cmd,val) 2507 /** @ingroup socket */ 2508 #define ioctl(s,cmd,argp) lwip_ioctl(s,cmd,argp) 2509 #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */ 2510 #endif /* LWIP_COMPAT_SOCKETS != 2 */ 2511 2512 #endif /* LWIP_COMPAT_SOCKETS */ 2513 2514 #ifdef __cplusplus 2515 } 2516 #endif 2517 2518 #endif /* LWIP_SOCKET */ 2519 2520 #endif /* LWIP_HDR_SOCKETS_H */ 2521