LCOV - code coverage report
Current view: top level - zephyr/net - socket.h Coverage Total Hit
Test: new.info Lines: 100.0 % 206 206
Test Date: 2025-09-25 19:22:35

            Line data    Source code
       1            1 : /**
       2              :  * @file
       3              :  * @brief BSD Sockets compatible API definitions
       4              :  *
       5              :  * An API for applications to use BSD Sockets like API.
       6              :  */
       7              : 
       8              : /*
       9              :  * Copyright (c) 2017-2018 Linaro Limited
      10              :  * Copyright (c) 2021 Nordic Semiconductor
      11              :  * Copyright (c) 2025 Aerlync Labs Inc.
      12              :  * Copyright 2025 NXP
      13              :  *
      14              :  * SPDX-License-Identifier: Apache-2.0
      15              :  */
      16              : 
      17              : #ifndef ZEPHYR_INCLUDE_NET_SOCKET_H_
      18              : #define ZEPHYR_INCLUDE_NET_SOCKET_H_
      19              : 
      20              : /**
      21              :  * @brief BSD Sockets compatible API
      22              :  * @defgroup bsd_sockets BSD Sockets compatible API
      23              :  * @since 1.9
      24              :  * @version 1.0.0
      25              :  * @ingroup networking
      26              :  * @{
      27              :  */
      28              : 
      29              : #include <zephyr/kernel.h>
      30              : #include <sys/types.h>
      31              : #include <zephyr/types.h>
      32              : #include <zephyr/device.h>
      33              : #include <zephyr/net/net_ip.h>
      34              : #include <zephyr/net/socket_select.h>
      35              : #include <zephyr/net/socket_poll.h>
      36              : #include <zephyr/sys/iterable_sections.h>
      37              : #include <zephyr/sys/fdtable.h>
      38              : #include <zephyr/net/dns_resolve.h>
      39              : #include <stdlib.h>
      40              : 
      41              : #ifdef __cplusplus
      42              : extern "C" {
      43              : #endif
      44              : 
      45              : /**
      46              :  * @name Options for poll()
      47              :  * @{
      48              :  */
      49              : /* ZSOCK_POLL* values are compatible with Linux */
      50              : /** zsock_poll: Poll for readability */
      51            1 : #define ZSOCK_POLLIN 1
      52              : /** zsock_poll: Poll for exceptional condition */
      53            1 : #define ZSOCK_POLLPRI 2
      54              : /** zsock_poll: Poll for writability */
      55            1 : #define ZSOCK_POLLOUT 4
      56              : /** zsock_poll: Poll results in error condition (output value only) */
      57            1 : #define ZSOCK_POLLERR 8
      58              : /** zsock_poll: Poll detected closed connection (output value only) */
      59            1 : #define ZSOCK_POLLHUP 0x10
      60              : /** zsock_poll: Invalid socket (output value only) */
      61            1 : #define ZSOCK_POLLNVAL 0x20
      62              : /** @} */
      63              : 
      64              : /**
      65              :  * @name Options for sending and receiving data
      66              :  * @{
      67              :  */
      68              : /** zsock_recv: Read data without removing it from socket input queue */
      69            1 : #define ZSOCK_MSG_PEEK 0x02
      70              : /** zsock_recvmsg: Control data buffer too small.
      71              :  */
      72            1 : #define ZSOCK_MSG_CTRUNC 0x08
      73              : /** zsock_recv: return the real length of the datagram, even when it was longer
      74              :  *  than the passed buffer
      75              :  */
      76            1 : #define ZSOCK_MSG_TRUNC 0x20
      77              : /** zsock_recv/zsock_send: Override operation to non-blocking */
      78            1 : #define ZSOCK_MSG_DONTWAIT 0x40
      79              : /** zsock_recv: block until the full amount of data can be returned */
      80            1 : #define ZSOCK_MSG_WAITALL 0x100
      81              : /** @} */
      82              : 
      83              : /**
      84              :  * @name Options for shutdown() function
      85              :  * @{
      86              :  */
      87              : /* Well-known values, e.g. from Linux man 2 shutdown:
      88              :  * "The constants SHUT_RD, SHUT_WR, SHUT_RDWR have the value 0, 1, 2,
      89              :  * respectively". Some software uses numeric values.
      90              :  */
      91              : /** zsock_shutdown: Shut down for reading */
      92            1 : #define ZSOCK_SHUT_RD 0
      93              : /** zsock_shutdown: Shut down for writing */
      94            1 : #define ZSOCK_SHUT_WR 1
      95              : /** zsock_shutdown: Shut down for both reading and writing */
      96            1 : #define ZSOCK_SHUT_RDWR 2
      97              : /** @} */
      98              : 
      99              : /**
     100              :  * @defgroup secure_sockets_options Socket options for TLS
     101              :  * @since 1.13
     102              :  * @version 0.8.0
     103              :  * @{
     104              :  */
     105              : /**
     106              :  * @name Socket options for TLS
     107              :  * @{
     108              :  */
     109              : 
     110              : /** Protocol level for TLS.
     111              :  *  Here, the same socket protocol level for TLS as in Linux was used.
     112              :  */
     113            1 : #define SOL_TLS 282
     114              : 
     115              : /** Socket option to select TLS credentials to use. It accepts and returns an
     116              :  *  array of sec_tag_t that indicate which TLS credentials should be used with
     117              :  *  specific socket.
     118              :  */
     119            1 : #define TLS_SEC_TAG_LIST 1
     120              : /** Write-only socket option to set hostname. It accepts a string containing
     121              :  *  the hostname (may be NULL to disable hostname verification). By default,
     122              :  *  hostname check is enforced for TLS clients.
     123              :  */
     124            1 : #define TLS_HOSTNAME 2
     125              : /** Socket option to select ciphersuites to use. It accepts and returns an array
     126              :  *  of integers with IANA assigned ciphersuite identifiers.
     127              :  *  If not set, socket will allow all ciphersuites available in the system
     128              :  *  (mbedTLS default behavior).
     129              :  */
     130            1 : #define TLS_CIPHERSUITE_LIST 3
     131              : /** Read-only socket option to read a ciphersuite chosen during TLS handshake.
     132              :  *  It returns an integer containing an IANA assigned ciphersuite identifier
     133              :  *  of chosen ciphersuite.
     134              :  */
     135            1 : #define TLS_CIPHERSUITE_USED 4
     136              : /** Write-only socket option to set peer verification level for TLS connection.
     137              :  *  This option accepts an integer with a peer verification level, compatible
     138              :  *  with mbedTLS values:
     139              :  *    - 0 - none
     140              :  *    - 1 - optional
     141              :  *    - 2 - required
     142              :  *
     143              :  *  If not set, socket will use mbedTLS defaults (none for servers, required
     144              :  *  for clients).
     145              :  */
     146            1 : #define TLS_PEER_VERIFY 5
     147              : /** Write-only socket option to set role for DTLS connection. This option
     148              :  *  is irrelevant for TLS connections, as for them role is selected based on
     149              :  *  connect()/listen() usage. By default, DTLS will assume client role.
     150              :  *  This option accepts an integer with a TLS role, compatible with
     151              :  *  mbedTLS values:
     152              :  *    - 0 - client
     153              :  *    - 1 - server
     154              :  */
     155            1 : #define TLS_DTLS_ROLE 6
     156              : /** Socket option for setting the supported Application Layer Protocols.
     157              :  *  It accepts and returns a const char array of NULL terminated strings
     158              :  *  representing the supported application layer protocols listed during
     159              :  *  the TLS handshake.
     160              :  */
     161            1 : #define TLS_ALPN_LIST 7
     162              : /** Socket option to set DTLS min handshake timeout. The timeout starts at min,
     163              :  *  and upon retransmission the timeout is doubled util max is reached.
     164              :  *  Min and max arguments are separate options. The time unit is ms.
     165              :  */
     166            1 : #define TLS_DTLS_HANDSHAKE_TIMEOUT_MIN 8
     167              : 
     168              : /** Socket option to set DTLS max handshake timeout. The timeout starts at min,
     169              :  *  and upon retransmission the timeout is doubled util max is reached.
     170              :  *  Min and max arguments are separate options. The time unit is ms.
     171              :  */
     172            1 : #define TLS_DTLS_HANDSHAKE_TIMEOUT_MAX 9
     173              : 
     174              : /** Socket option for preventing certificates from being copied to the mbedTLS
     175              :  *  heap if possible. The option is only effective for DER certificates and is
     176              :  *  ignored for PEM certificates.
     177              :  */
     178            1 : #define TLS_CERT_NOCOPY        10
     179              : /** TLS socket option to use with offloading. The option instructs the network
     180              :  *  stack only to offload underlying TCP/UDP communication. The TLS/DTLS
     181              :  *  operation is handled by a native TLS/DTLS socket implementation from Zephyr.
     182              :  *
     183              :  *  Note, that this option is only applicable if socket dispatcher is used
     184              :  *  (CONFIG_NET_SOCKETS_OFFLOAD_DISPATCHER is enabled).
     185              :  *  In such case, it should be the first socket option set on a newly created
     186              :  *  socket. After that, the application may use SO_BINDTODEVICE to choose the
     187              :  *  dedicated network interface for the underlying TCP/UDP socket.
     188              :  */
     189            1 : #define TLS_NATIVE 11
     190              : /** Socket option to control TLS session caching on a socket. Accepted values:
     191              :  *  - 0 - Disabled.
     192              :  *  - 1 - Enabled.
     193              :  */
     194            1 : #define TLS_SESSION_CACHE 12
     195              : /** Write-only socket option to purge session cache immediately.
     196              :  *  This option accepts any value.
     197              :  */
     198            1 : #define TLS_SESSION_CACHE_PURGE 13
     199              : /** Write-only socket option to control DTLS CID.
     200              :  *  The option accepts an integer, indicating the setting.
     201              :  *  Accepted values for the option are: 0, 1 and 2.
     202              :  *  Effective when set before connecting to the socket.
     203              :  *  - 0 - DTLS CID will be disabled.
     204              :  *  - 1 - DTLS CID will be enabled, and a 0 length CID value to be sent to the
     205              :  *        peer.
     206              :  *  - 2 - DTLS CID will be enabled, and the most recent value set with
     207              :  *        TLS_DTLS_CID_VALUE will be sent to the peer. Otherwise, a random value
     208              :  *        will be used.
     209              :  */
     210            1 : #define TLS_DTLS_CID 14
     211              : /** Read-only socket option to get DTLS CID status.
     212              :  *  The option accepts a pointer to an integer, indicating the setting upon
     213              :  *  return.
     214              :  *  Returned values for the option are:
     215              :  *  - 0 - DTLS CID is disabled.
     216              :  *  - 1 - DTLS CID is received on the downlink.
     217              :  *  - 2 - DTLS CID is sent to the uplink.
     218              :  *  - 3 - DTLS CID is used in both directions.
     219              :  */
     220            1 : #define TLS_DTLS_CID_STATUS 15
     221              : /** Socket option to set or get the value of the DTLS connection ID to be
     222              :  *  used for the DTLS session.
     223              :  *  The option accepts a byte array, holding the CID value.
     224              :  */
     225            1 : #define TLS_DTLS_CID_VALUE 16
     226              : /** Read-only socket option to get the value of the DTLS connection ID
     227              :  *  received from the peer.
     228              :  *  The option accepts a pointer to a byte array, holding the CID value upon
     229              :  *  return. The optlen returned will be 0 if the peer did not provide a
     230              :  *  connection ID, otherwise will contain the length of the CID value.
     231              :  */
     232            1 : #define TLS_DTLS_PEER_CID_VALUE 17
     233              : /** Socket option to configure DTLS socket behavior on connect().
     234              :  *  If set, DTLS connect() will execute the handshake with the configured peer.
     235              :  *  This is the default behavior.
     236              :  *  Otherwise, DTLS connect() will only configure peer address (as with regular
     237              :  *  UDP socket) and will not attempt to execute DTLS handshake. The handshake
     238              :  *  will take place in consecutive send()/recv() call.
     239              :  */
     240            1 : #define TLS_DTLS_HANDSHAKE_ON_CONNECT 18
     241              : /** Read-only socket option to obtain the result of the certificate verification
     242              :  *  from the most recent handshake if TLS_PEER_VERIFY_OPTIONAL was set on the
     243              :  *  socket.
     244              :  *  The option accepts a pointer to a 32-bit unsigned integer, holding the
     245              :  *  verification result on return. A result of 0 indicates that verification
     246              :  *  was successful, otherwise the verification result is indicated by a set of
     247              :  *  flags. For mbed TLS backend, the flags are defined in "X509 Verify codes"
     248              :  *  section of x509.h header.
     249              :  */
     250            1 : #define TLS_CERT_VERIFY_RESULT 19
     251              : /** Write-only socket option to configure a certificate verification callback for
     252              :  *  the socket. The option accepts a pointer to a @ref tls_cert_verify_cb
     253              :  *  structure, which contains pointers to the actual callback function and
     254              :  *  application-defined context.
     255              :  *
     256              :  *  If set, the certificate verification is delegated to the registered callback.
     257              :  *  In such case it's the application's responsibility to verify the provided
     258              :  *  certificates and decide whether to proceed or abort the handshake.
     259              :  *
     260              :  *  The option is only available if CONFIG_NET_SOCKETS_TLS_CERT_VERIFY_CALLBACK
     261              :  *  Kconfig option is enabled.
     262              :  */
     263            1 : #define TLS_CERT_VERIFY_CALLBACK 20
     264              : 
     265              : /* Valid values for @ref TLS_PEER_VERIFY option */
     266            1 : #define TLS_PEER_VERIFY_NONE 0     /**< Peer verification disabled. */
     267            1 : #define TLS_PEER_VERIFY_OPTIONAL 1 /**< Peer verification optional. */
     268            1 : #define TLS_PEER_VERIFY_REQUIRED 2 /**< Peer verification required. */
     269              : 
     270              : /* Valid values for @ref TLS_DTLS_ROLE option */
     271            1 : #define TLS_DTLS_ROLE_CLIENT 0 /**< Client role in a DTLS session. */
     272            1 : #define TLS_DTLS_ROLE_SERVER 1 /**< Server role in a DTLS session. */
     273              : 
     274              : /* Valid values for @ref TLS_CERT_NOCOPY option */
     275            1 : #define TLS_CERT_NOCOPY_NONE 0     /**< Cert duplicated in heap */
     276            1 : #define TLS_CERT_NOCOPY_OPTIONAL 1 /**< Cert not copied in heap if DER */
     277              : 
     278              : /* Valid values for @ref TLS_SESSION_CACHE option */
     279            1 : #define TLS_SESSION_CACHE_DISABLED 0 /**< Disable TLS session caching. */
     280            1 : #define TLS_SESSION_CACHE_ENABLED 1 /**< Enable TLS session caching. */
     281              : 
     282              : /* Valid values for @ref TLS_DTLS_CID (Connection ID) option */
     283            1 : #define TLS_DTLS_CID_DISABLED           0 /**< CID is disabled  */
     284            1 : #define TLS_DTLS_CID_SUPPORTED          1 /**< CID is supported */
     285            1 : #define TLS_DTLS_CID_ENABLED            2 /**< CID is enabled   */
     286              : 
     287              : /* Valid values for @ref TLS_DTLS_CID_STATUS option */
     288            1 : #define TLS_DTLS_CID_STATUS_DISABLED            0 /**< CID is disabled */
     289            1 : #define TLS_DTLS_CID_STATUS_DOWNLINK            1 /**< CID is in use by us */
     290            1 : #define TLS_DTLS_CID_STATUS_UPLINK              2 /**< CID is in use by peer */
     291            1 : #define TLS_DTLS_CID_STATUS_BIDIRECTIONAL       3 /**< CID is in use by us and peer */
     292              : 
     293              : /** Data structure for @ref TLS_CERT_VERIFY_CALLBACK socket option. */
     294            1 : struct tls_cert_verify_cb {
     295              :         /** A pointer to the certificate verification callback function.
     296              :          *
     297              :          *  The actual callback function type is defined by mbed TLS, see
     298              :          *  documentation of mbedtls_x509_crt_verify() function.
     299              :          */
     300            1 :         void *cb;
     301              : 
     302              :         /** A pointer to an opaque context passed to the callback. */
     303            1 :         void *ctx;
     304              : };
     305              : /** @} */ /* for @name */
     306              : /** @} */ /* for @defgroup */
     307              : 
     308              : /**
     309              :  * @brief Definition used when querying address information.
     310              :  *
     311              :  * A linked list of these descriptors is returned by getaddrinfo(). The struct
     312              :  * is also passed as hints when calling the getaddrinfo() function.
     313              :  */
     314            1 : struct zsock_addrinfo {
     315            1 :         struct zsock_addrinfo *ai_next; /**< Pointer to next address entry */
     316            1 :         int ai_flags;             /**< Additional options */
     317            1 :         int ai_family;            /**< Address family of the returned addresses */
     318            1 :         int ai_socktype;          /**< Socket type, for example SOCK_STREAM or SOCK_DGRAM */
     319            1 :         int ai_protocol;          /**< Protocol for addresses, 0 means any protocol */
     320            1 :         int ai_eflags;            /**< Extended flags for special usage */
     321            1 :         socklen_t ai_addrlen;     /**< Length of the socket address */
     322            1 :         struct sockaddr *ai_addr; /**< Pointer to the address */
     323            1 :         char *ai_canonname;       /**< Optional official name of the host */
     324              : 
     325              : /** @cond INTERNAL_HIDDEN */
     326              :         struct sockaddr _ai_addr;
     327              :         char _ai_canonname[DNS_MAX_NAME_SIZE + 1];
     328              : /** @endcond */
     329              : };
     330              : 
     331              : /**
     332              :  * @brief Obtain a file descriptor's associated net context
     333              :  *
     334              :  * With CONFIG_USERSPACE enabled, the kernel's object permission system
     335              :  * must apply to socket file descriptors. When a socket is opened, by default
     336              :  * only the caller has permission, access by other threads will fail unless
     337              :  * they have been specifically granted permission.
     338              :  *
     339              :  * This is achieved by tagging data structure definitions that implement the
     340              :  * underlying object associated with a network socket file descriptor with
     341              :  * '__net_socket`. All pointers to instances of these will be known to the
     342              :  * kernel as kernel objects with type K_OBJ_NET_SOCKET.
     343              :  *
     344              :  * This API is intended for threads that need to grant access to the object
     345              :  * associated with a particular file descriptor to another thread. The
     346              :  * returned pointer represents the underlying K_OBJ_NET_SOCKET  and
     347              :  * may be passed to APIs like k_object_access_grant().
     348              :  *
     349              :  * In a system like Linux which has the notion of threads running in processes
     350              :  * in a shared virtual address space, this sort of management is unnecessary as
     351              :  * the scope of file descriptors is implemented at the process level.
     352              :  *
     353              :  * However in Zephyr the file descriptor scope is global, and MPU-based systems
     354              :  * are not able to implement a process-like model due to the lack of memory
     355              :  * virtualization hardware. They use discrete object permissions and memory
     356              :  * domains instead to define thread access scope.
     357              :  *
     358              :  * User threads will have no direct access to the returned object
     359              :  * and will fault if they try to access its memory; the pointer can only be
     360              :  * used to make permission assignment calls, which follow exactly the rules
     361              :  * for other kernel objects like device drivers and IPC.
     362              :  *
     363              :  * @param sock file descriptor
     364              :  * @return pointer to associated network socket object, or NULL if the
     365              :  *         file descriptor wasn't valid or the caller had no access permission
     366              :  */
     367            1 : __syscall void *zsock_get_context_object(int sock);
     368              : 
     369              : /**
     370              :  * @brief Create a network socket
     371              :  *
     372              :  * @details
     373              :  * See POSIX.1-2017 article
     374              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html
     375              :  * for normative description.
     376              :  * This function is also exposed as `socket()`
     377              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     378              :  *
     379              :  * If CONFIG_USERSPACE is enabled, the caller will be granted access to the
     380              :  * context object associated with the returned file descriptor.
     381              :  * @see zsock_get_context_object()
     382              :  *
     383              :  */
     384            1 : __syscall int zsock_socket(int family, int type, int proto);
     385              : 
     386              : /**
     387              :  * @brief Create an unnamed pair of connected sockets
     388              :  *
     389              :  * @details
     390              :  * See POSIX.1-2017 article
     391              :  * https://pubs.opengroup.org/onlinepubs/009695399/functions/socketpair.html
     392              :  * for normative description.
     393              :  * This function is also exposed as `socketpair()`
     394              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     395              :  */
     396            1 : __syscall int zsock_socketpair(int family, int type, int proto, int *sv);
     397              : 
     398              : /**
     399              :  * @brief Close a network socket
     400              :  *
     401              :  * @details
     402              :  * Close a network socket.
     403              :  * This function is also exposed as `close()`
     404              :  * if @kconfig{CONFIG_POSIX_API} is defined (in which case it
     405              :  * may conflict with generic POSIX `close()` function).
     406              :  */
     407            1 : __syscall int zsock_close(int sock);
     408              : 
     409              : /**
     410              :  * @brief Shutdown socket send/receive operations
     411              :  *
     412              :  * @details
     413              :  * See POSIX.1-2017 article
     414              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/shutdown.html
     415              :  * for normative description, but currently this function has no effect in
     416              :  * Zephyr and provided solely for compatibility with existing code.
     417              :  * This function is also exposed as `shutdown()`
     418              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     419              :  */
     420            1 : __syscall int zsock_shutdown(int sock, int how);
     421              : 
     422              : /**
     423              :  * @brief Bind a socket to a local network address
     424              :  *
     425              :  * @details
     426              :  * See POSIX.1-2017 article
     427              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html
     428              :  * for normative description.
     429              :  * This function is also exposed as `bind()`
     430              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     431              :  */
     432            1 : __syscall int zsock_bind(int sock, const struct sockaddr *addr,
     433              :                          socklen_t addrlen);
     434              : 
     435              : /**
     436              :  * @brief Connect a socket to a peer network address
     437              :  *
     438              :  * @details
     439              :  * See POSIX.1-2017 article
     440              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html
     441              :  * for normative description.
     442              :  * This function is also exposed as `connect()`
     443              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     444              :  */
     445            1 : __syscall int zsock_connect(int sock, const struct sockaddr *addr,
     446              :                             socklen_t addrlen);
     447              : 
     448              : /**
     449              :  * @brief Set up a STREAM socket to accept peer connections
     450              :  *
     451              :  * @details
     452              :  * See POSIX.1-2017 article
     453              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html
     454              :  * for normative description.
     455              :  * This function is also exposed as `listen()`
     456              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     457              :  */
     458            1 : __syscall int zsock_listen(int sock, int backlog);
     459              : 
     460              : /**
     461              :  * @brief Accept a connection on listening socket
     462              :  *
     463              :  * @details
     464              :  * See POSIX.1-2017 article
     465              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html
     466              :  * for normative description.
     467              :  * This function is also exposed as `accept()`
     468              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     469              :  */
     470            1 : __syscall int zsock_accept(int sock, struct sockaddr *addr, socklen_t *addrlen);
     471              : 
     472              : /**
     473              :  * @brief Send data to an arbitrary network address
     474              :  *
     475              :  * @details
     476              :  * See POSIX.1-2017 article
     477              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html
     478              :  * for normative description.
     479              :  * This function is also exposed as `sendto()`
     480              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     481              :  */
     482            1 : __syscall ssize_t zsock_sendto(int sock, const void *buf, size_t len,
     483              :                                int flags, const struct sockaddr *dest_addr,
     484              :                                socklen_t addrlen);
     485              : 
     486              : /**
     487              :  * @brief Send data to a connected peer
     488              :  *
     489              :  * @details
     490              :  * See POSIX.1-2017 article
     491              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html
     492              :  * for normative description.
     493              :  * This function is also exposed as `send()`
     494              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     495              :  */
     496            1 : static inline ssize_t zsock_send(int sock, const void *buf, size_t len,
     497              :                                  int flags)
     498              : {
     499              :         return zsock_sendto(sock, buf, len, flags, NULL, 0);
     500              : }
     501              : 
     502              : /**
     503              :  * @brief Send data to an arbitrary network address
     504              :  *
     505              :  * @details
     506              :  * See POSIX.1-2017 article
     507              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html
     508              :  * for normative description.
     509              :  * This function is also exposed as `sendmsg()`
     510              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     511              :  */
     512            1 : __syscall ssize_t zsock_sendmsg(int sock, const struct msghdr *msg,
     513              :                                 int flags);
     514              : 
     515              : /**
     516              :  * @brief Receive data from an arbitrary network address
     517              :  *
     518              :  * @details
     519              :  * See POSIX.1-2017 article
     520              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html
     521              :  * for normative description.
     522              :  * This function is also exposed as `recvfrom()`
     523              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     524              :  */
     525            1 : __syscall ssize_t zsock_recvfrom(int sock, void *buf, size_t max_len,
     526              :                                  int flags, struct sockaddr *src_addr,
     527              :                                  socklen_t *addrlen);
     528              : 
     529              : /**
     530              :  * @brief Receive a message from an arbitrary network address
     531              :  *
     532              :  * @details
     533              :  * See POSIX.1-2017 article
     534              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html
     535              :  * for normative description.
     536              :  * This function is also exposed as `recvmsg()`
     537              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     538              :  */
     539            1 : __syscall ssize_t zsock_recvmsg(int sock, struct msghdr *msg, int flags);
     540              : 
     541              : /**
     542              :  * @brief Receive data from a connected peer
     543              :  *
     544              :  * @details
     545              :  * See POSIX.1-2017 article
     546              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html
     547              :  * for normative description.
     548              :  * This function is also exposed as `recv()`
     549              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     550              :  */
     551            1 : static inline ssize_t zsock_recv(int sock, void *buf, size_t max_len,
     552              :                                  int flags)
     553              : {
     554              :         return zsock_recvfrom(sock, buf, max_len, flags, NULL, NULL);
     555              : }
     556              : 
     557              : /**
     558              :  * @brief Control blocking/non-blocking mode of a socket
     559              :  *
     560              :  * @details
     561              :  * This functions allow to (only) configure a socket for blocking or
     562              :  * non-blocking operation (O_NONBLOCK).
     563              :  * This function is also exposed as `fcntl()`
     564              :  * if @kconfig{CONFIG_POSIX_API} is defined (in which case
     565              :  * it may conflict with generic POSIX `fcntl()` function).
     566              :  */
     567            1 : __syscall int zsock_fcntl_impl(int sock, int cmd, int flags);
     568              : 
     569              : /** @cond INTERNAL_HIDDEN */
     570              : 
     571              : /*
     572              :  * Need this wrapper because newer GCC versions got too smart and "typecheck"
     573              :  * even macros.
     574              :  */
     575              : static inline int zsock_fcntl_wrapper(int sock, int cmd, ...)
     576              : {
     577              :         va_list args;
     578              :         int flags;
     579              : 
     580              :         va_start(args, cmd);
     581              :         flags = va_arg(args, int);
     582              :         va_end(args);
     583              :         return zsock_fcntl_impl(sock, cmd, flags);
     584              : }
     585              : 
     586              : #define zsock_fcntl zsock_fcntl_wrapper
     587              : 
     588              : /** @endcond */
     589              : 
     590              : /**
     591              :  * @brief Control underlying socket parameters
     592              :  *
     593              :  * @details
     594              :  * See POSIX.1-2017 article
     595              :  * https://pubs.opengroup.org/onlinepubs/9699919799/functions/ioctl.html
     596              :  * for normative description.
     597              :  * This function enables querying or manipulating underlying socket parameters.
     598              :  * Currently supported @p request values include `ZFD_IOCTL_FIONBIO`, and
     599              :  * `ZFD_IOCTL_FIONREAD`, to set non-blocking mode, and query the number of
     600              :  * bytes available to read, respectively.
     601              :  * This function is also exposed as `ioctl()`
     602              :  * if @kconfig{CONFIG_POSIX_API} is defined (in which case
     603              :  * it may conflict with generic POSIX `ioctl()` function).
     604              :  */
     605            1 : __syscall int zsock_ioctl_impl(int sock, unsigned long request, va_list ap);
     606              : 
     607              : /** @cond INTERNAL_HIDDEN */
     608              : 
     609              : static inline int zsock_ioctl_wrapper(int sock, unsigned long request, ...)
     610              : {
     611              :         int ret;
     612              :         va_list args;
     613              : 
     614              :         va_start(args, request);
     615              :         ret = zsock_ioctl_impl(sock, request, args);
     616              :         va_end(args);
     617              : 
     618              :         return ret;
     619              : }
     620              : 
     621              : #define zsock_ioctl zsock_ioctl_wrapper
     622              : 
     623              : /** @endcond */
     624              : 
     625              : /**
     626              :  * @brief Efficiently poll multiple sockets for events
     627              :  *
     628              :  * @details
     629              :  * See POSIX.1-2017 article
     630              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html
     631              :  * for normative description.
     632              :  * This function is also exposed as `poll()`
     633              :  * if @kconfig{CONFIG_POSIX_API} is defined (in which case
     634              :  * it may conflict with generic POSIX `poll()` function).
     635              :  */
     636            1 : static inline int zsock_poll(struct zsock_pollfd *fds, int nfds, int timeout)
     637              : {
     638              :         return zvfs_poll(fds, nfds, timeout);
     639              : }
     640              : 
     641              : /**
     642              :  * @brief Get various socket options
     643              :  *
     644              :  * @details
     645              :  * See POSIX.1-2017 article
     646              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
     647              :  * for normative description. In Zephyr this function supports a subset of
     648              :  * socket options described by POSIX, but also some additional options
     649              :  * available in Linux (some options are dummy and provided to ease porting
     650              :  * of existing code).
     651              :  * This function is also exposed as `getsockopt()`
     652              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     653              :  */
     654            1 : __syscall int zsock_getsockopt(int sock, int level, int optname,
     655              :                                void *optval, socklen_t *optlen);
     656              : 
     657              : /**
     658              :  * @brief Set various socket options
     659              :  *
     660              :  * @details
     661              :  * See POSIX.1-2017 article
     662              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html
     663              :  * for normative description. In Zephyr this function supports a subset of
     664              :  * socket options described by POSIX, but also some additional options
     665              :  * available in Linux (some options are dummy and provided to ease porting
     666              :  * of existing code).
     667              :  * This function is also exposed as `setsockopt()`
     668              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     669              :  */
     670            1 : __syscall int zsock_setsockopt(int sock, int level, int optname,
     671              :                                const void *optval, socklen_t optlen);
     672              : 
     673              : /**
     674              :  * @brief Get peer name
     675              :  *
     676              :  * @details
     677              :  * See POSIX.1-2017 article
     678              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html
     679              :  * for normative description.
     680              :  * This function is also exposed as `getpeername()`
     681              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     682              :  */
     683            1 : __syscall int zsock_getpeername(int sock, struct sockaddr *addr,
     684              :                                 socklen_t *addrlen);
     685              : 
     686              : /**
     687              :  * @brief Get socket name
     688              :  *
     689              :  * @details
     690              :  * See POSIX.1-2017 article
     691              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html
     692              :  * for normative description.
     693              :  * This function is also exposed as `getsockname()`
     694              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     695              :  */
     696            1 : __syscall int zsock_getsockname(int sock, struct sockaddr *addr,
     697              :                                 socklen_t *addrlen);
     698              : 
     699              : /**
     700              :  * @brief Get local host name
     701              :  *
     702              :  * @details
     703              :  * See POSIX.1-2017 article
     704              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/gethostname.html
     705              :  * for normative description.
     706              :  * This function is also exposed as `gethostname()`
     707              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     708              :  */
     709            1 : __syscall int zsock_gethostname(char *buf, size_t len);
     710              : 
     711              : /**
     712              :  * @brief Convert network address from internal to numeric ASCII form
     713              :  *
     714              :  * @details
     715              :  * See POSIX.1-2017 article
     716              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_ntop.html
     717              :  * for normative description.
     718              :  * This function is also exposed as `inet_ntop()`
     719              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     720              :  */
     721            1 : static inline char *zsock_inet_ntop(sa_family_t family, const void *src,
     722              :                                     char *dst, size_t size)
     723              : {
     724              :         return net_addr_ntop(family, src, dst, size);
     725              : }
     726              : 
     727              : /**
     728              :  * @brief Convert network address from numeric ASCII form to internal representation
     729              :  *
     730              :  * @details
     731              :  * See POSIX.1-2017 article
     732              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_pton.html
     733              :  * for normative description.
     734              :  * This function is also exposed as `inet_pton()`
     735              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     736              :  */
     737            1 : __syscall int zsock_inet_pton(sa_family_t family, const char *src, void *dst);
     738              : 
     739              : /** @cond INTERNAL_HIDDEN */
     740              : __syscall int z_zsock_getaddrinfo_internal(const char *host,
     741              :                                            const char *service,
     742              :                                            const struct zsock_addrinfo *hints,
     743              :                                            struct zsock_addrinfo *res);
     744              : /** @endcond */
     745              : 
     746              : /* Flags for getaddrinfo() hints. */
     747              : 
     748              : /**
     749              :  * @name Flags for getaddrinfo() hints
     750              :  * @{
     751              :  */
     752              : /** Address for bind() (vs for connect()) */
     753            1 : #define AI_PASSIVE 0x1
     754              : /** Fill in ai_canonname */
     755            1 : #define AI_CANONNAME 0x2
     756              : /** Assume host address is in numeric notation, don't DNS lookup */
     757            1 : #define AI_NUMERICHOST 0x4
     758              : /** May return IPv4 mapped address for IPv6  */
     759            1 : #define AI_V4MAPPED 0x8
     760              : /** May return both native IPv6 and mapped IPv4 address for IPv6 */
     761            1 : #define AI_ALL 0x10
     762              : /** IPv4/IPv6 support depends on local system config */
     763            1 : #define AI_ADDRCONFIG 0x20
     764              : /** Assume service (port) is numeric */
     765            1 : #define AI_NUMERICSERV 0x400
     766              : /** Extra flags present (see RFC 5014) */
     767            1 : #define AI_EXTFLAGS 0x800
     768              : /** @} */
     769              : 
     770              : /**
     771              :  * @brief Resolve a domain name to one or more network addresses
     772              :  *
     773              :  * @details
     774              :  * See POSIX.1-2017 article
     775              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html
     776              :  * for normative description.
     777              :  * This function is also exposed as `getaddrinfo()`
     778              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     779              :  */
     780            1 : int zsock_getaddrinfo(const char *host, const char *service,
     781              :                       const struct zsock_addrinfo *hints,
     782              :                       struct zsock_addrinfo **res);
     783              : 
     784              : /**
     785              :  * @brief Free results returned by zsock_getaddrinfo()
     786              :  *
     787              :  * @details
     788              :  * See POSIX.1-2017 article
     789              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/freeaddrinfo.html
     790              :  * for normative description.
     791              :  * This function is also exposed as `freeaddrinfo()`
     792              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     793              :  */
     794            1 : void zsock_freeaddrinfo(struct zsock_addrinfo *ai);
     795              : 
     796              : /**
     797              :  * @brief Convert zsock_getaddrinfo() error code to textual message
     798              :  *
     799              :  * @details
     800              :  * See POSIX.1-2017 article
     801              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/gai_strerror.html
     802              :  * for normative description.
     803              :  * This function is also exposed as `gai_strerror()`
     804              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     805              :  */
     806            1 : const char *zsock_gai_strerror(int errcode);
     807              : 
     808              : /**
     809              :  * @name Flags for getnameinfo()
     810              :  * @{
     811              :  */
     812              : /** zsock_getnameinfo(): Resolve to numeric address. */
     813            1 : #define NI_NUMERICHOST 1
     814              : /** zsock_getnameinfo(): Resolve to numeric port number. */
     815            1 : #define NI_NUMERICSERV 2
     816              : /** zsock_getnameinfo(): Return only hostname instead of FQDN */
     817            1 : #define NI_NOFQDN 4
     818              : /** zsock_getnameinfo(): Dummy option for compatibility */
     819            1 : #define NI_NAMEREQD 8
     820              : /** zsock_getnameinfo(): Dummy option for compatibility */
     821            1 : #define NI_DGRAM 16
     822              : 
     823              : /* POSIX extensions */
     824              : 
     825              : /** zsock_getnameinfo(): Max supported hostname length */
     826              : #ifndef NI_MAXHOST
     827            1 : #define NI_MAXHOST 64
     828              : #endif
     829              : /** @} */
     830              : 
     831              : /**
     832              :  * @brief Resolve a network address to a domain name or ASCII address
     833              :  *
     834              :  * @details
     835              :  * See POSIX.1-2017 article
     836              :  * http://pubs.opengroup.org/onlinepubs/9699919799/functions/getnameinfo.html
     837              :  * for normative description.
     838              :  * This function is also exposed as `getnameinfo()`
     839              :  * if @kconfig{CONFIG_POSIX_API} is defined.
     840              :  */
     841            1 : int zsock_getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
     842              :                       char *host, socklen_t hostlen,
     843              :                       char *serv, socklen_t servlen, int flags);
     844              : 
     845              : /**
     846              :  * @name Network interface name description
     847              :  * @{
     848              :  */
     849              : /** Network interface name length */
     850              : #if defined(CONFIG_NET_INTERFACE_NAME)
     851              : #define IFNAMSIZ CONFIG_NET_INTERFACE_NAME_LEN
     852              : #else
     853            1 : #define IFNAMSIZ Z_DEVICE_MAX_NAME_LEN
     854              : #endif
     855              : 
     856              : /** Interface description structure */
     857            1 : struct ifreq {
     858            1 :         char ifr_name[IFNAMSIZ]; /**< Network interface name */
     859              : };
     860              : /** @} */
     861              : 
     862              : /**
     863              :  * @name Socket level options (SOL_SOCKET)
     864              :  * @{
     865              :  */
     866              : /** Socket-level option */
     867            1 : #define SOL_SOCKET 1
     868              : 
     869              : /* Socket options for SOL_SOCKET level */
     870              : 
     871              : /** Recording debugging information (ignored, for compatibility) */
     872            1 : #define SO_DEBUG 1
     873              : /** address reuse */
     874            1 : #define SO_REUSEADDR 2
     875              : /** Type of the socket */
     876            1 : #define SO_TYPE 3
     877              : /** Async error */
     878            1 : #define SO_ERROR 4
     879              : /** Bypass normal routing and send directly to host (ignored, for compatibility) */
     880            1 : #define SO_DONTROUTE 5
     881              : /** Transmission of broadcast messages is supported (ignored, for compatibility) */
     882            1 : #define SO_BROADCAST 6
     883              : 
     884              : /** Size of socket send buffer */
     885            1 : #define SO_SNDBUF 7
     886              : /** Size of socket recv buffer */
     887            1 : #define SO_RCVBUF 8
     888              : 
     889              : /** Enable sending keep-alive messages on connections */
     890            1 : #define SO_KEEPALIVE 9
     891              : /** Place out-of-band data into receive stream (ignored, for compatibility) */
     892            1 : #define SO_OOBINLINE 10
     893              : /** Socket priority */
     894            1 : #define SO_PRIORITY 12
     895              : /** Socket lingers on close (ignored, for compatibility) */
     896            1 : #define SO_LINGER 13
     897              : /** Allow multiple sockets to reuse a single port */
     898            1 : #define SO_REUSEPORT 15
     899              : 
     900              : /** Receive low watermark (ignored, for compatibility) */
     901            1 : #define SO_RCVLOWAT 18
     902              : /** Send low watermark (ignored, for compatibility) */
     903            1 : #define SO_SNDLOWAT 19
     904              : 
     905              : /**
     906              :  * Receive timeout
     907              :  * Applies to receive functions like recv(), but not to connect()
     908              :  */
     909            1 : #define SO_RCVTIMEO 20
     910              : /** Send timeout */
     911            1 : #define SO_SNDTIMEO 21
     912              : 
     913              : /** Bind a socket to an interface */
     914            1 : #define SO_BINDTODEVICE 25
     915              : 
     916              : /** Socket accepts incoming connections (ignored, for compatibility) */
     917            1 : #define SO_ACCEPTCONN 30
     918              : 
     919              : /** Timestamp TX RX or both packets. Supports multiple timestamp sources. */
     920            1 : #define SO_TIMESTAMPING 37
     921              : 
     922              : /** Protocol used with the socket */
     923            1 : #define SO_PROTOCOL 38
     924              : 
     925              : /** Domain used with SOCKET */
     926            1 : #define SO_DOMAIN 39
     927              : 
     928              : /** Enable SOCKS5 for Socket */
     929            1 : #define SO_SOCKS5 60
     930              : 
     931              : /** Socket TX time (when the data should be sent) */
     932            1 : #define SO_TXTIME 61
     933              : /** Socket TX time (same as SO_TXTIME) */
     934            1 : #define SCM_TXTIME SO_TXTIME
     935              : 
     936              : /** Timestamp generation flags */
     937              : 
     938              : /** Request RX timestamps generated by network adapter. */
     939            1 : #define SOF_TIMESTAMPING_RX_HARDWARE BIT(0)
     940              : /**
     941              :  * Request TX timestamps generated by network adapter.
     942              :  * This can be enabled via socket option or control messages.
     943              :  */
     944            1 : #define SOF_TIMESTAMPING_TX_HARDWARE BIT(1)
     945              : 
     946              : /** */
     947              : 
     948              : /** @} */
     949              : 
     950              : /**
     951              :  * @name TCP level options (IPPROTO_TCP)
     952              :  * @{
     953              :  */
     954              : /* Socket options for IPPROTO_TCP level */
     955              : /** Disable TCP buffering (ignored, for compatibility) */
     956            1 : #define TCP_NODELAY 1
     957              : /** Start keepalives after this period (seconds) */
     958            1 : #define TCP_KEEPIDLE 2
     959              : /** Interval between keepalives (seconds) */
     960            1 : #define TCP_KEEPINTVL 3
     961              : /** Number of keepalives before dropping connection */
     962            1 : #define TCP_KEEPCNT 4
     963              : 
     964              : /** @} */
     965              : 
     966              : /**
     967              :  * @name IPv4 level options (IPPROTO_IP)
     968              :  * @{
     969              :  */
     970              : /* Socket options for IPPROTO_IP level */
     971              : /** Set or receive the Type-Of-Service value for an outgoing packet. */
     972            1 : #define IP_TOS 1
     973              : 
     974              : /** Set or receive the Time-To-Live value for an outgoing packet. */
     975            1 : #define IP_TTL 2
     976              : 
     977              : /** Pass an IP_PKTINFO ancillary message that contains a
     978              :  *  pktinfo structure that supplies some information about the
     979              :  *  incoming packet.
     980              :  */
     981            1 : #define IP_PKTINFO 8
     982              : 
     983              : /**
     984              :  * @brief Incoming IPv4 packet information.
     985              :  *
     986              :  * Used as ancillary data when calling recvmsg() and IP_PKTINFO socket
     987              :  * option is set.
     988              :  */
     989            1 : struct in_pktinfo {
     990            1 :         unsigned int   ipi_ifindex;  /**< Network interface index */
     991            1 :         struct in_addr ipi_spec_dst; /**< Local address */
     992            1 :         struct in_addr ipi_addr;     /**< Header Destination address */
     993              : };
     994              : 
     995              : /** Pass an IP_RECVTTL ancillary message that contains information
     996              :  *  about the time to live of the incoming packet.
     997              :  */
     998            1 : #define IP_RECVTTL 12
     999              : 
    1000              : /** Retrieve the current known path MTU of the current socket. Returns an
    1001              :  *  integer. IP_MTU is valid only for getsockopt and can be employed only when
    1002              :  *  the socket has been connected.
    1003              :  */
    1004            1 : #define IP_MTU 14
    1005              : 
    1006              : /** Set IPv4 multicast datagram network interface. */
    1007            1 : #define IP_MULTICAST_IF 32
    1008              : /** Set IPv4 multicast TTL value. */
    1009            1 : #define IP_MULTICAST_TTL 33
    1010              : /** Set IPv4 multicast loop value. */
    1011            1 : #define IP_MULTICAST_LOOP 34
    1012              : /** Join IPv4 multicast group. */
    1013            1 : #define IP_ADD_MEMBERSHIP 35
    1014              : /** Leave IPv4 multicast group. */
    1015            1 : #define IP_DROP_MEMBERSHIP 36
    1016              : 
    1017              : /**
    1018              :  * @brief Struct used when joining or leaving a IPv4 multicast group.
    1019              :  */
    1020            1 : struct ip_mreqn {
    1021            1 :         struct in_addr imr_multiaddr; /**< IP multicast group address */
    1022            1 :         struct in_addr imr_address;   /**< IP address of local interface */
    1023            1 :         int            imr_ifindex;   /**< Network interface index */
    1024              : };
    1025              : 
    1026              : /**
    1027              :  * @brief Struct used when setting a IPv4 multicast network interface.
    1028              :  */
    1029            1 : struct ip_mreq  {
    1030            1 :         struct in_addr imr_multiaddr;   /**< IP multicast group address */
    1031            1 :         struct in_addr imr_interface;   /**< IP address of local interface */
    1032              : };
    1033              : 
    1034              : /** Clamp down the global port range for a given socket */
    1035            1 : #define IP_LOCAL_PORT_RANGE 51
    1036              : 
    1037              : /** @} */
    1038              : 
    1039              : /**
    1040              :  * @name IPv6 level options (IPPROTO_IPV6)
    1041              :  * @{
    1042              :  */
    1043              : /* Socket options for IPPROTO_IPV6 level */
    1044              : /** Set the unicast hop limit for the socket. */
    1045            1 : #define IPV6_UNICAST_HOPS       16
    1046              : 
    1047              : /** Set multicast output network interface index for the socket. */
    1048            1 : #define IPV6_MULTICAST_IF       17
    1049              : 
    1050              : /** Set the multicast hop limit for the socket. */
    1051            1 : #define IPV6_MULTICAST_HOPS 18
    1052              : 
    1053              : /** Set the multicast loop bit for the socket. */
    1054            1 : #define IPV6_MULTICAST_LOOP 19
    1055              : 
    1056              : /** Join IPv6 multicast group. */
    1057            1 : #define IPV6_ADD_MEMBERSHIP 20
    1058              : 
    1059              : /** Leave IPv6 multicast group. */
    1060            1 : #define IPV6_DROP_MEMBERSHIP 21
    1061              : 
    1062              : /** Join IPv6 multicast group. */
    1063            1 : #define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
    1064              : 
    1065              : /** Leave IPv6 multicast group. */
    1066            1 : #define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
    1067              : 
    1068              : /**
    1069              :  * @brief Struct used when joining or leaving a IPv6 multicast group.
    1070              :  */
    1071            1 : struct ipv6_mreq {
    1072              :         /** IPv6 multicast address of group */
    1073            1 :         struct in6_addr ipv6mr_multiaddr;
    1074              : 
    1075              :         /** Network interface index of the local IPv6 address */
    1076            1 :         int ipv6mr_ifindex;
    1077              : };
    1078              : 
    1079              : /** For getsockopt(), retrieve the current known IPv6 path MTU of the given socket.
    1080              :  * Valid only when the socket has been connected.
    1081              :  * For setsockopt(), set the MTU to be used for the socket. The MTU is limited by
    1082              :  * the device MTU or the path MTU when path MTU discovery is enabled.
    1083              :  */
    1084            1 : #define IPV6_MTU 24
    1085              : 
    1086              : /** Don't support IPv4 access */
    1087            1 : #define IPV6_V6ONLY 26
    1088              : 
    1089              : /** Pass an IPV6_RECVPKTINFO ancillary message that contains a
    1090              :  *  in6_pktinfo structure that supplies some information about the
    1091              :  *  incoming packet. See RFC 3542.
    1092              :  */
    1093            1 : #define IPV6_RECVPKTINFO 49
    1094              : 
    1095              : /** Option which returns an in6_pktinfo structure in ancillary data */
    1096            1 : #define IPV6_PKTINFO 50
    1097              : 
    1098              : /** Pass an IPV6_RECVHOPLIMIT ancillary message that contains information
    1099              :  *  about the hop limit of the incoming packet. See RFC 3542.
    1100              :  */
    1101            1 : #define IPV6_RECVHOPLIMIT 51
    1102              : 
    1103              : /** Set or receive the hoplimit value for an outgoing packet. */
    1104            1 : #define IPV6_HOPLIMIT 52
    1105              : 
    1106              : /** RFC5014: Source address selection. */
    1107            1 : #define IPV6_ADDR_PREFERENCES   72
    1108              : 
    1109              : /** Prefer temporary address as source. */
    1110            1 : #define IPV6_PREFER_SRC_TMP             0x0001
    1111              : /** Prefer public address as source. */
    1112            1 : #define IPV6_PREFER_SRC_PUBLIC          0x0002
    1113              : /** Either public or temporary address is selected as a default source
    1114              :  *  depending on the output interface configuration (this is the default value).
    1115              :  *  This is Linux specific option not found in the RFC.
    1116              :  */
    1117            1 : #define IPV6_PREFER_SRC_PUBTMP_DEFAULT  0x0100
    1118              : /** Prefer Care-of address as source. Ignored in Zephyr. */
    1119            1 : #define IPV6_PREFER_SRC_COA             0x0004
    1120              : /** Prefer Home address as source. Ignored in Zephyr. */
    1121            1 : #define IPV6_PREFER_SRC_HOME            0x0400
    1122              : /** Prefer CGA (Cryptographically Generated Address) address as source. Ignored in Zephyr. */
    1123            1 : #define IPV6_PREFER_SRC_CGA             0x0008
    1124              : /** Prefer non-CGA address as source. Ignored in Zephyr. */
    1125            1 : #define IPV6_PREFER_SRC_NONCGA          0x0800
    1126              : 
    1127              : /**
    1128              :  * @brief Incoming IPv6 packet information.
    1129              :  *
    1130              :  * Used as ancillary data when calling recvmsg() and IPV6_RECVPKTINFO socket
    1131              :  * option is set.
    1132              :  */
    1133            1 : struct in6_pktinfo {
    1134            1 :         struct in6_addr ipi6_addr;    /**< Destination IPv6 address */
    1135            1 :         unsigned int    ipi6_ifindex; /**< Receive interface index */
    1136              : };
    1137              : 
    1138              : /** Set or receive the traffic class value for an outgoing packet. */
    1139            1 : #define IPV6_TCLASS 67
    1140              : /** @} */
    1141              : 
    1142              : /**
    1143              :  * @name Backlog size for listen()
    1144              :  * @{
    1145              :  */
    1146              : /** listen: The maximum backlog queue length */
    1147            1 : #define SOMAXCONN 128
    1148              : /** @} */
    1149              : 
    1150              : /**
    1151              :  * @name Macros for checking special IPv6 addresses.
    1152              :  * @{
    1153              :  */
    1154              : /** Check unspecified IPv6 address. */
    1155            1 : #define IN6_IS_ADDR_UNSPECIFIED(addr) \
    1156              :         net_ipv6_addr_cmp(net_ipv6_unspecified_address(), addr)
    1157              : 
    1158              : /** Check loopback IPv6 address. */
    1159            1 : #define IN6_IS_ADDR_LOOPBACK(addr) net_ipv6_is_addr_loopback(addr)
    1160              : 
    1161              : /** Check IPv6 multicast address */
    1162            1 : #define IN6_IS_ADDR_MULTICAST(addr) net_ipv6_is_addr_mcast(addr)
    1163              : 
    1164              : /** Check IPv6 link local address */
    1165            1 : #define IN6_IS_ADDR_LINKLOCAL(addr) net_ipv6_is_ll_addr(addr)
    1166              : 
    1167              : /** Check IPv6 site local address */
    1168            1 : #define IN6_IS_ADDR_SITELOCAL(addr) net_ipv6_is_sl_addr(addr)
    1169              : 
    1170              : /** Check IPv6 v4 mapped address */
    1171            1 : #define IN6_IS_ADDR_V4MAPPED(addr) net_ipv6_addr_is_v4_mapped(addr)
    1172              : 
    1173              : /** Check IPv6 multicast global address */
    1174            1 : #define IN6_IS_ADDR_MC_GLOBAL(addr) net_ipv6_is_addr_mcast_global(addr)
    1175              : 
    1176              : /** Check IPv6 multicast node local address */
    1177            1 : #define IN6_IS_ADDR_MC_NODELOCAL(addr) net_ipv6_is_addr_mcast_iface(addr)
    1178              : 
    1179              : /** Check IPv6 multicast link local address */
    1180            1 : #define IN6_IS_ADDR_MC_LINKLOCAL(addr) net_ipv6_is_addr_mcast_link(addr)
    1181              : 
    1182              : /** Check IPv6 multicast site local address */
    1183            1 : #define IN6_IS_ADDR_MC_SITELOCAL(addr) net_ipv6_is_addr_mcast_site(addr)
    1184              : 
    1185              : /** Check IPv6 multicast organization local address */
    1186            1 : #define IN6_IS_ADDR_MC_ORGLOCAL(addr) net_ipv6_is_addr_mcast_org(addr)
    1187              : 
    1188              : /** @} */
    1189              : 
    1190              : /** @cond INTERNAL_HIDDEN */
    1191              : /**
    1192              :  * @brief Registration information for a given BSD socket family.
    1193              :  */
    1194              : struct net_socket_register {
    1195              :         int family;
    1196              :         bool is_offloaded;
    1197              :         bool (*is_supported)(int family, int type, int proto);
    1198              :         int (*handler)(int family, int type, int proto);
    1199              : #if defined(CONFIG_NET_SOCKETS_OBJ_CORE)
    1200              :         /* Store also the name of the socket type in order to be able to
    1201              :          * print it later.
    1202              :          */
    1203              :         const char * const name;
    1204              : #endif
    1205              : };
    1206              : 
    1207              : #define NET_SOCKET_DEFAULT_PRIO CONFIG_NET_SOCKETS_PRIORITY_DEFAULT
    1208              : 
    1209              : #define NET_SOCKET_GET_NAME(socket_name, prio)  \
    1210              :         __net_socket_register_##prio##_##socket_name
    1211              : 
    1212              : #if defined(CONFIG_NET_SOCKETS_OBJ_CORE)
    1213              : #define K_OBJ_TYPE_SOCK  K_OBJ_TYPE_ID_GEN("SOCK")
    1214              : 
    1215              : #define NET_SOCKET_REGISTER_NAME(_name)         \
    1216              :         .name = STRINGIFY(_name),
    1217              : #else
    1218              : #define NET_SOCKET_REGISTER_NAME(_name)
    1219              : #endif
    1220              : 
    1221              : #define _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, _is_offloaded) \
    1222              :         static const STRUCT_SECTION_ITERABLE(net_socket_register,       \
    1223              :                         NET_SOCKET_GET_NAME(socket_name, prio)) = {     \
    1224              :                 .family = _family,                                      \
    1225              :                 .is_offloaded = _is_offloaded,                          \
    1226              :                 .is_supported = _is_supported,                          \
    1227              :                 .handler = _handler,                                    \
    1228              :                 NET_SOCKET_REGISTER_NAME(socket_name)                   \
    1229              :         }
    1230              : 
    1231              : #define NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler) \
    1232              :         _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, false)
    1233              : 
    1234              : #define NET_SOCKET_OFFLOAD_REGISTER(socket_name, prio, _family, _is_supported, _handler) \
    1235              :         _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, true)
    1236              : 
    1237              : struct socket_op_vtable {
    1238              :         struct fd_op_vtable fd_vtable;
    1239              :         int (*shutdown)(void *obj, int how);
    1240              :         int (*bind)(void *obj, const struct sockaddr *addr, socklen_t addrlen);
    1241              :         int (*connect)(void *obj, const struct sockaddr *addr,
    1242              :                        socklen_t addrlen);
    1243              :         int (*listen)(void *obj, int backlog);
    1244              :         int (*accept)(void *obj, struct sockaddr *addr, socklen_t *addrlen);
    1245              :         ssize_t (*sendto)(void *obj, const void *buf, size_t len, int flags,
    1246              :                           const struct sockaddr *dest_addr, socklen_t addrlen);
    1247              :         ssize_t (*recvfrom)(void *obj, void *buf, size_t max_len, int flags,
    1248              :                             struct sockaddr *src_addr, socklen_t *addrlen);
    1249              :         int (*getsockopt)(void *obj, int level, int optname,
    1250              :                           void *optval, socklen_t *optlen);
    1251              :         int (*setsockopt)(void *obj, int level, int optname,
    1252              :                           const void *optval, socklen_t optlen);
    1253              :         ssize_t (*sendmsg)(void *obj, const struct msghdr *msg, int flags);
    1254              :         ssize_t (*recvmsg)(void *obj, struct msghdr *msg, int flags);
    1255              :         int (*getpeername)(void *obj, struct sockaddr *addr,
    1256              :                            socklen_t *addrlen);
    1257              :         int (*getsockname)(void *obj, struct sockaddr *addr,
    1258              :                            socklen_t *addrlen);
    1259              : };
    1260              : 
    1261              : /** @endcond */
    1262              : 
    1263              : #ifdef __cplusplus
    1264              : }
    1265              : #endif
    1266              : 
    1267              : #include <zephyr/syscalls/socket.h>
    1268              : 
    1269              : /**
    1270              :  * @}
    1271              :  */
    1272              : 
    1273              : /* Avoid circular loops with POSIX socket headers.
    1274              :  * We have these includes here so that we do not need
    1275              :  * to change the applications that were only including
    1276              :  * zephyr/net/socket.h header file.
    1277              :  *
    1278              :  * Additionally, if non-zephyr-prefixed headers are used here,
    1279              :  * native_sim pulls in those from the host rather than Zephyr's.
    1280              :  */
    1281              : #if defined(CONFIG_POSIX_API)
    1282              : #if !defined(ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_)
    1283              : #include <zephyr/posix/arpa/inet.h>
    1284              : #endif
    1285              : #if !defined(ZEPHYR_INCLUDE_POSIX_NETDB_H_)
    1286              : #include <zephyr/posix/netdb.h>
    1287              : #endif
    1288              : #if !defined(ZEPHYR_INCLUDE_POSIX_UNISTD_H_)
    1289              : #include <zephyr/posix/unistd.h>
    1290              : #endif
    1291              : #if !defined(ZEPHYR_INCLUDE_POSIX_POLL_H_)
    1292              : #include <zephyr/posix/poll.h>
    1293              : #endif
    1294              : #if !defined(ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_)
    1295              : #include <zephyr/posix/sys/socket.h>
    1296              : #endif
    1297              : #endif /* CONFIG_POSIX_API */
    1298              : 
    1299              : #endif /* ZEPHYR_INCLUDE_NET_SOCKET_H_ */
        

Generated by: LCOV version 2.0-1