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