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 #define ZSOCK_POLLIN 1
52 /** zsock_poll: Poll for exceptional condition */
53 #define ZSOCK_POLLPRI 2
54 /** zsock_poll: Poll for writability */
55 #define ZSOCK_POLLOUT 4
56 /** zsock_poll: Poll results in error condition (output value only) */
57 #define ZSOCK_POLLERR 8
58 /** zsock_poll: Poll detected closed connection (output value only) */
59 #define ZSOCK_POLLHUP 0x10
60 /** zsock_poll: Invalid socket (output value only) */
61 #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 #define ZSOCK_MSG_PEEK 0x02
70 /** zsock_recvmsg: Control data buffer too small.
71 */
72 #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 #define ZSOCK_MSG_TRUNC 0x20
77 /** zsock_recv/zsock_send: Override operation to non-blocking */
78 #define ZSOCK_MSG_DONTWAIT 0x40
79 /** zsock_recv: block until the full amount of data can be returned */
80 #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 #define ZSOCK_SHUT_RD 0
93 /** zsock_shutdown: Shut down for writing */
94 #define ZSOCK_SHUT_WR 1
95 /** zsock_shutdown: Shut down for both reading and writing */
96 #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 #define ZSOCK_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 #define ZSOCK_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 #define ZSOCK_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 #define ZSOCK_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 #define ZSOCK_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 #define ZSOCK_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 #define ZSOCK_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 #define ZSOCK_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 #define ZSOCK_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 #define ZSOCK_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 #define ZSOCK_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 #define ZSOCK_TLS_NATIVE 11
190 /** Socket option to control TLS session caching on a socket. Accepted values:
191 * - 0 - Disabled.
192 * - 1 - Enabled.
193 */
194 #define ZSOCK_TLS_SESSION_CACHE 12
195 /** Write-only socket option to purge session cache immediately.
196 * This option accepts any value.
197 */
198 #define ZSOCK_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 #define ZSOCK_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 #define ZSOCK_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 #define ZSOCK_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 #define ZSOCK_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 #define ZSOCK_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 #define ZSOCK_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 zsock_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 #define ZSOCK_TLS_CERT_VERIFY_CALLBACK 20
264
265 /* Valid values for @ref TLS_PEER_VERIFY option */
266 #define ZSOCK_TLS_PEER_VERIFY_NONE 0 /**< Peer verification disabled. */
267 #define ZSOCK_TLS_PEER_VERIFY_OPTIONAL 1 /**< Peer verification optional. */
268 #define ZSOCK_TLS_PEER_VERIFY_REQUIRED 2 /**< Peer verification required. */
269
270 /* Valid values for @ref TLS_DTLS_ROLE option */
271 #define ZSOCK_TLS_DTLS_ROLE_CLIENT 0 /**< Client role in a DTLS session. */
272 #define ZSOCK_TLS_DTLS_ROLE_SERVER 1 /**< Server role in a DTLS session. */
273
274 /* Valid values for @ref TLS_CERT_NOCOPY option */
275 #define ZSOCK_TLS_CERT_NOCOPY_NONE 0 /**< Cert duplicated in heap */
276 #define ZSOCK_TLS_CERT_NOCOPY_OPTIONAL 1 /**< Cert not copied in heap if DER */
277
278 /* Valid values for @ref TLS_SESSION_CACHE option */
279 #define ZSOCK_TLS_SESSION_CACHE_DISABLED 0 /**< Disable TLS session caching. */
280 #define ZSOCK_TLS_SESSION_CACHE_ENABLED 1 /**< Enable TLS session caching. */
281
282 /* Valid values for @ref TLS_DTLS_CID (Connection ID) option */
283 #define ZSOCK_TLS_DTLS_CID_DISABLED 0 /**< CID is disabled */
284 #define ZSOCK_TLS_DTLS_CID_SUPPORTED 1 /**< CID is supported */
285 #define ZSOCK_TLS_DTLS_CID_ENABLED 2 /**< CID is enabled */
286
287 /* Valid values for @ref TLS_DTLS_CID_STATUS option */
288 #define ZSOCK_TLS_DTLS_CID_STATUS_DISABLED 0 /**< CID is disabled */
289 #define ZSOCK_TLS_DTLS_CID_STATUS_DOWNLINK 1 /**< CID is in use by us */
290 #define ZSOCK_TLS_DTLS_CID_STATUS_UPLINK 2 /**< CID is in use by peer */
291 #define ZSOCK_TLS_DTLS_CID_STATUS_BIDIRECTIONAL 3 /**< CID is in use by us and peer */
292
293 /** Data structure for @ref ZSOCK_TLS_CERT_VERIFY_CALLBACK socket option. */
294 struct zsock_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 void *cb;
301
302 /** A pointer to an opaque context passed to the callback. */
303 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 struct zsock_addrinfo {
315 struct zsock_addrinfo *ai_next; /**< Pointer to next address entry */
316 int ai_flags; /**< Additional options */
317 int ai_family; /**< Address family of the returned addresses */
318 int ai_socktype; /**< Socket type, for example NET_SOCK_STREAM or NET_SOCK_DGRAM */
319 int ai_protocol; /**< Protocol for addresses, 0 means any protocol */
320 int ai_eflags; /**< Extended flags for special usage */
321 net_socklen_t ai_addrlen; /**< Length of the socket address */
322 struct net_sockaddr *ai_addr; /**< Pointer to the address */
323 char *ai_canonname; /**< Optional official name of the host */
324
325 /** @cond INTERNAL_HIDDEN */
326 struct net_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 __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 __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 __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 __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 __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 __syscall int zsock_bind(int sock, const struct net_sockaddr *addr,
433 net_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 __syscall int zsock_connect(int sock, const struct net_sockaddr *addr,
446 net_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 __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 __syscall int zsock_accept(int sock, struct net_sockaddr *addr, net_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 __syscall ssize_t zsock_sendto(int sock, const void *buf, size_t len,
483 int flags, const struct net_sockaddr *dest_addr,
484 net_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 */
zsock_send(int sock,const void * buf,size_t len,int flags)496 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 __syscall ssize_t zsock_sendmsg(int sock, const struct net_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 __syscall ssize_t zsock_recvfrom(int sock, void *buf, size_t max_len,
526 int flags, struct net_sockaddr *src_addr,
527 net_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 __syscall ssize_t zsock_recvmsg(int sock, struct net_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 */
zsock_recv(int sock,void * buf,size_t max_len,int flags)551 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 __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 */
zsock_fcntl_wrapper(int sock,int cmd,...)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 __syscall int zsock_ioctl_impl(int sock, unsigned long request, va_list ap);
606
607 /** @cond INTERNAL_HIDDEN */
608
zsock_ioctl_wrapper(int sock,unsigned long request,...)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 */
zsock_poll(struct zsock_pollfd * fds,int nfds,int timeout)636 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 __syscall int zsock_getsockopt(int sock, int level, int optname,
655 void *optval, net_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 __syscall int zsock_setsockopt(int sock, int level, int optname,
671 const void *optval, net_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 __syscall int zsock_getpeername(int sock, struct net_sockaddr *addr,
684 net_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 __syscall int zsock_getsockname(int sock, struct net_sockaddr *addr,
697 net_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 __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 */
zsock_inet_ntop(net_sa_family_t family,const void * src,char * dst,size_t size)721 static inline char *zsock_inet_ntop(net_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 __syscall int zsock_inet_pton(net_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 #define ZSOCK_AI_PASSIVE 0x1
754 /** Fill in ai_canonname */
755 #define ZSOCK_AI_CANONNAME 0x2
756 /** Assume host address is in numeric notation, don't DNS lookup */
757 #define ZSOCK_AI_NUMERICHOST 0x4
758 /** May return IPv4 mapped address for IPv6 */
759 #define ZSOCK_AI_V4MAPPED 0x8
760 /** May return both native IPv6 and mapped IPv4 address for IPv6 */
761 #define ZSOCK_AI_ALL 0x10
762 /** IPv4/IPv6 support depends on local system config */
763 #define ZSOCK_AI_ADDRCONFIG 0x20
764 /** Assume service (port) is numeric */
765 #define ZSOCK_AI_NUMERICSERV 0x400
766 /** Extra flags present (see RFC 5014) */
767 #define ZSOCK_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 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 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 const char *zsock_gai_strerror(int errcode);
807
808 /**
809 * @name Flags for getnameinfo()
810 * @{
811 */
812 /** zsock_getnameinfo(): Resolve to numeric address. */
813 #define ZSOCK_NI_NUMERICHOST 1
814 /** zsock_getnameinfo(): Resolve to numeric port number. */
815 #define ZSOCK_NI_NUMERICSERV 2
816 /** zsock_getnameinfo(): Return only hostname instead of FQDN */
817 #define ZSOCK_NI_NOFQDN 4
818 /** zsock_getnameinfo(): Dummy option for compatibility */
819 #define ZSOCK_NI_NAMEREQD 8
820 /** zsock_getnameinfo(): Dummy option for compatibility */
821 #define ZSOCK_NI_DGRAM 16
822
823 /* POSIX extensions */
824
825 /** zsock_getnameinfo(): Max supported hostname length */
826 #ifndef ZSOCK_NI_MAXHOST
827 #define ZSOCK_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 int zsock_getnameinfo(const struct net_sockaddr *addr, net_socklen_t addrlen,
842 char *host, net_socklen_t hostlen,
843 char *serv, net_socklen_t servlen, int flags);
844
845 /**
846 * @name Socket level options (ZSOCK_SOL_SOCKET)
847 * @{
848 */
849 /** Socket-level option */
850 #define ZSOCK_SOL_SOCKET 1
851
852 /* Socket options for SOL_SOCKET level */
853
854 /** Recording debugging information (ignored, for compatibility) */
855 #define ZSOCK_SO_DEBUG 1
856 /** address reuse */
857 #define ZSOCK_SO_REUSEADDR 2
858 /** Type of the socket */
859 #define ZSOCK_SO_TYPE 3
860 /** Async error */
861 #define ZSOCK_SO_ERROR 4
862 /** Bypass normal routing and send directly to host (ignored, for compatibility) */
863 #define ZSOCK_SO_DONTROUTE 5
864 /** Transmission of broadcast messages is supported (ignored, for compatibility) */
865 #define ZSOCK_SO_BROADCAST 6
866
867 /** Size of socket send buffer */
868 #define ZSOCK_SO_SNDBUF 7
869 /** Size of socket recv buffer */
870 #define ZSOCK_SO_RCVBUF 8
871
872 /** Enable sending keep-alive messages on connections */
873 #define ZSOCK_SO_KEEPALIVE 9
874 /** Place out-of-band data into receive stream (ignored, for compatibility) */
875 #define ZSOCK_SO_OOBINLINE 10
876 /** Socket priority */
877 #define ZSOCK_SO_PRIORITY 12
878 /** Socket lingers on close (ignored, for compatibility) */
879 #define ZSOCK_SO_LINGER 13
880 /** Allow multiple sockets to reuse a single port */
881 #define ZSOCK_SO_REUSEPORT 15
882
883 /** Receive low watermark (ignored, for compatibility) */
884 #define ZSOCK_SO_RCVLOWAT 18
885 /** Send low watermark (ignored, for compatibility) */
886 #define ZSOCK_SO_SNDLOWAT 19
887
888 /**
889 * Receive timeout
890 * Applies to receive functions like recv(), but not to connect()
891 */
892 #define ZSOCK_SO_RCVTIMEO 20
893 /** Send timeout */
894 #define ZSOCK_SO_SNDTIMEO 21
895
896 /** Bind a socket to an interface */
897 #define ZSOCK_SO_BINDTODEVICE 25
898
899 /** Socket accepts incoming connections (ignored, for compatibility) */
900 #define ZSOCK_SO_ACCEPTCONN 30
901
902 /** Timestamp TX RX or both packets. Supports multiple timestamp sources. */
903 #define ZSOCK_SO_TIMESTAMPING 37
904
905 /** Protocol used with the socket */
906 #define ZSOCK_SO_PROTOCOL 38
907
908 /** Domain used with SOCKET */
909 #define ZSOCK_SO_DOMAIN 39
910
911 /** Enable SOCKS5 for Socket */
912 #define ZSOCK_SO_SOCKS5 60
913
914 /** Socket TX time (when the data should be sent) */
915 #define ZSOCK_SO_TXTIME 61
916 /** Socket TX time (same as SO_TXTIME) */
917 #define ZSOCK_SCM_TXTIME ZSOCK_SO_TXTIME
918
919 /** Timestamp generation flags */
920
921 /** Request RX timestamps generated by network adapter. */
922 #define ZSOCK_SOF_TIMESTAMPING_RX_HARDWARE BIT(0)
923 /**
924 * Request TX timestamps generated by network adapter.
925 * This can be enabled via socket option or control messages.
926 */
927 #define ZSOCK_SOF_TIMESTAMPING_TX_HARDWARE BIT(1)
928
929 /** */
930
931 /** @} */
932
933 /**
934 * @name TCP level options (NET_IPPROTO_TCP)
935 * @{
936 */
937 /* Socket options for NET_IPPROTO_TCP level */
938 /** Disable TCP buffering (ignored, for compatibility) */
939 #define ZSOCK_TCP_NODELAY 1
940 /** Start keepalives after this period (seconds) */
941 #define ZSOCK_TCP_KEEPIDLE 2
942 /** Interval between keepalives (seconds) */
943 #define ZSOCK_TCP_KEEPINTVL 3
944 /** Number of keepalives before dropping connection */
945 #define ZSOCK_TCP_KEEPCNT 4
946
947 /** @} */
948
949 /**
950 * @name IPv4 level options (NET_IPPROTO_IP)
951 * @{
952 */
953 /* Socket options for IPPROTO_IP level */
954 /** Set or receive the Type-Of-Service value for an outgoing packet. */
955 #define ZSOCK_IP_TOS 1
956
957 /** Set or receive the Time-To-Live value for an outgoing packet. */
958 #define ZSOCK_IP_TTL 2
959
960 /** Pass an IP_PKTINFO ancillary message that contains a
961 * pktinfo structure that supplies some information about the
962 * incoming packet.
963 */
964 #define ZSOCK_IP_PKTINFO 8
965
966 /** Pass an IP_RECVTTL ancillary message that contains information
967 * about the time to live of the incoming packet.
968 */
969 #define ZSOCK_IP_RECVTTL 12
970
971 /** Retrieve the current known path MTU of the current socket. Returns an
972 * integer. ZSOCK_IP_MTU is valid only for getsockopt and can be employed only when
973 * the socket has been connected.
974 */
975 #define ZSOCK_IP_MTU 14
976
977 /** Set IPv4 multicast datagram network interface. */
978 #define ZSOCK_IP_MULTICAST_IF 32
979 /** Set IPv4 multicast TTL value. */
980 #define ZSOCK_IP_MULTICAST_TTL 33
981 /** Set IPv4 multicast loop value. */
982 #define ZSOCK_IP_MULTICAST_LOOP 34
983 /** Join IPv4 multicast group. */
984 #define ZSOCK_IP_ADD_MEMBERSHIP 35
985 /** Leave IPv4 multicast group. */
986 #define ZSOCK_IP_DROP_MEMBERSHIP 36
987
988 /** Clamp down the global port range for a given socket */
989 #define ZSOCK_IP_LOCAL_PORT_RANGE 51
990
991 /** @} */
992
993 /**
994 * @name IPv6 level options (NET_IPPROTO_IPV6)
995 * @{
996 */
997 /* Socket options for NET_IPPROTO_IPV6 level */
998 /** Set the unicast hop limit for the socket. */
999 #define ZSOCK_IPV6_UNICAST_HOPS 16
1000
1001 /** Set multicast output network interface index for the socket. */
1002 #define ZSOCK_IPV6_MULTICAST_IF 17
1003
1004 /** Set the multicast hop limit for the socket. */
1005 #define ZSOCK_IPV6_MULTICAST_HOPS 18
1006
1007 /** Set the multicast loop bit for the socket. */
1008 #define ZSOCK_IPV6_MULTICAST_LOOP 19
1009
1010 /** Join IPv6 multicast group. */
1011 #define ZSOCK_IPV6_ADD_MEMBERSHIP 20
1012
1013 /** Leave IPv6 multicast group. */
1014 #define ZSOCK_IPV6_DROP_MEMBERSHIP 21
1015
1016 /** Join IPv6 multicast group. */
1017 #define ZSOCK_IPV6_JOIN_GROUP ZSOCK_IPV6_ADD_MEMBERSHIP
1018
1019 /** Leave IPv6 multicast group. */
1020 #define ZSOCK_IPV6_LEAVE_GROUP ZSOCK_IPV6_DROP_MEMBERSHIP
1021
1022 /** For getsockopt(), retrieve the current known IPv6 path MTU of the given socket.
1023 * Valid only when the socket has been connected.
1024 * For setsockopt(), set the MTU to be used for the socket. The MTU is limited by
1025 * the device MTU or the path MTU when path MTU discovery is enabled.
1026 */
1027 #define ZSOCK_IPV6_MTU 24
1028
1029 /** Don't support IPv4 access */
1030 #define ZSOCK_IPV6_V6ONLY 26
1031
1032 /** Pass an IPV6_RECVPKTINFO ancillary message that contains a
1033 * in6_pktinfo structure that supplies some information about the
1034 * incoming packet. See RFC 3542.
1035 */
1036 #define ZSOCK_IPV6_RECVPKTINFO 49
1037
1038 /** Option which returns an in6_pktinfo structure in ancillary data */
1039 #define ZSOCK_IPV6_PKTINFO 50
1040
1041 /** Pass an IPV6_RECVHOPLIMIT ancillary message that contains information
1042 * about the hop limit of the incoming packet. See RFC 3542.
1043 */
1044 #define ZSOCK_IPV6_RECVHOPLIMIT 51
1045
1046 /** Set or receive the hoplimit value for an outgoing packet. */
1047 #define ZSOCK_IPV6_HOPLIMIT 52
1048
1049 /** RFC5014: Source address selection. */
1050 #define ZSOCK_IPV6_ADDR_PREFERENCES 72
1051
1052 /** Prefer temporary address as source. */
1053 #define ZSOCK_IPV6_PREFER_SRC_TMP 0x0001
1054 /** Prefer public address as source. */
1055 #define ZSOCK_IPV6_PREFER_SRC_PUBLIC 0x0002
1056 /** Either public or temporary address is selected as a default source
1057 * depending on the output interface configuration (this is the default value).
1058 * This is Linux specific option not found in the RFC.
1059 */
1060 #define ZSOCK_IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100
1061 /** Prefer Care-of address as source. Ignored in Zephyr. */
1062 #define ZSOCK_IPV6_PREFER_SRC_COA 0x0004
1063 /** Prefer Home address as source. Ignored in Zephyr. */
1064 #define ZSOCK_IPV6_PREFER_SRC_HOME 0x0400
1065 /** Prefer CGA (Cryptographically Generated Address) address as source. Ignored in Zephyr. */
1066 #define ZSOCK_IPV6_PREFER_SRC_CGA 0x0008
1067 /** Prefer non-CGA address as source. Ignored in Zephyr. */
1068 #define ZSOCK_IPV6_PREFER_SRC_NONCGA 0x0800
1069
1070 /** Set or receive the traffic class value for an outgoing packet. */
1071 #define ZSOCK_IPV6_TCLASS 67
1072 /** @} */
1073
1074 /**
1075 * @name Backlog size for listen()
1076 * @{
1077 */
1078 /** listen: The maximum backlog queue length */
1079 #define ZSOCK_SOMAXCONN 128
1080 /** @} */
1081
1082 /**
1083 * @name Macros for checking special IPv6 addresses.
1084 * @{
1085 */
1086 /** Check unspecified IPv6 address. */
1087 #define ZSOCK_IN6_IS_ADDR_UNSPECIFIED(addr) \
1088 net_ipv6_addr_cmp(net_ipv6_unspecified_address(), addr)
1089
1090 /** Check loopback IPv6 address. */
1091 #define ZSOCK_IN6_IS_ADDR_LOOPBACK(addr) net_ipv6_is_addr_loopback(addr)
1092
1093 /** Check IPv6 multicast address */
1094 #define ZSOCK_IN6_IS_ADDR_MULTICAST(addr) net_ipv6_is_addr_mcast(addr)
1095
1096 /** Check IPv6 link local address */
1097 #define ZSOCK_IN6_IS_ADDR_LINKLOCAL(addr) net_ipv6_is_ll_addr(addr)
1098
1099 /** Check IPv6 site local address */
1100 #define ZSOCK_IN6_IS_ADDR_SITELOCAL(addr) net_ipv6_is_sl_addr(addr)
1101
1102 /** Check IPv6 v4 mapped address */
1103 #define ZSOCK_IN6_IS_ADDR_V4MAPPED(addr) net_ipv6_addr_is_v4_mapped(addr)
1104
1105 /** Check IPv6 multicast global address */
1106 #define ZSOCK_IN6_IS_ADDR_MC_GLOBAL(addr) net_ipv6_is_addr_mcast_global(addr)
1107
1108 /** Check IPv6 multicast node local address */
1109 #define ZSOCK_IN6_IS_ADDR_MC_NODELOCAL(addr) net_ipv6_is_addr_mcast_iface(addr)
1110
1111 /** Check IPv6 multicast link local address */
1112 #define ZSOCK_IN6_IS_ADDR_MC_LINKLOCAL(addr) net_ipv6_is_addr_mcast_link(addr)
1113
1114 /** Check IPv6 multicast site local address */
1115 #define ZSOCK_IN6_IS_ADDR_MC_SITELOCAL(addr) net_ipv6_is_addr_mcast_site(addr)
1116
1117 /** Check IPv6 multicast organization local address */
1118 #define ZSOCK_IN6_IS_ADDR_MC_ORGLOCAL(addr) net_ipv6_is_addr_mcast_org(addr)
1119
1120 /** @} */
1121
1122 /** @cond INTERNAL_HIDDEN */
1123 /**
1124 * @brief Registration information for a given BSD socket family.
1125 */
1126 struct net_socket_register {
1127 int family;
1128 bool is_offloaded;
1129 bool (*is_supported)(int family, int type, int proto);
1130 int (*handler)(int family, int type, int proto);
1131 #if defined(CONFIG_NET_SOCKETS_OBJ_CORE)
1132 /* Store also the name of the socket type in order to be able to
1133 * print it later.
1134 */
1135 const char * const name;
1136 #endif
1137 };
1138
1139 #define NET_SOCKET_DEFAULT_PRIO CONFIG_NET_SOCKETS_PRIORITY_DEFAULT
1140
1141 #define NET_SOCKET_GET_NAME(socket_name, prio) \
1142 __net_socket_register_##prio##_##socket_name
1143
1144 #if defined(CONFIG_NET_SOCKETS_OBJ_CORE)
1145 #define K_OBJ_TYPE_SOCK K_OBJ_TYPE_ID_GEN("SOCK")
1146
1147 #define NET_SOCKET_REGISTER_NAME(_name) \
1148 .name = STRINGIFY(_name),
1149 #else
1150 #define NET_SOCKET_REGISTER_NAME(_name)
1151 #endif
1152
1153 #define _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, _is_offloaded) \
1154 static const STRUCT_SECTION_ITERABLE(net_socket_register, \
1155 NET_SOCKET_GET_NAME(socket_name, prio)) = { \
1156 .family = _family, \
1157 .is_offloaded = _is_offloaded, \
1158 .is_supported = _is_supported, \
1159 .handler = _handler, \
1160 NET_SOCKET_REGISTER_NAME(socket_name) \
1161 }
1162
1163 #define NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler) \
1164 _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, false)
1165
1166 #define NET_SOCKET_OFFLOAD_REGISTER(socket_name, prio, _family, _is_supported, _handler) \
1167 _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, true)
1168
1169 struct socket_op_vtable {
1170 struct fd_op_vtable fd_vtable;
1171 int (*shutdown)(void *obj, int how);
1172 int (*bind)(void *obj, const struct net_sockaddr *addr, net_socklen_t addrlen);
1173 int (*connect)(void *obj, const struct net_sockaddr *addr,
1174 net_socklen_t addrlen);
1175 int (*listen)(void *obj, int backlog);
1176 int (*accept)(void *obj, struct net_sockaddr *addr, net_socklen_t *addrlen);
1177 ssize_t (*sendto)(void *obj, const void *buf, size_t len, int flags,
1178 const struct net_sockaddr *dest_addr, net_socklen_t addrlen);
1179 ssize_t (*recvfrom)(void *obj, void *buf, size_t max_len, int flags,
1180 struct net_sockaddr *src_addr, net_socklen_t *addrlen);
1181 int (*getsockopt)(void *obj, int level, int optname,
1182 void *optval, net_socklen_t *optlen);
1183 int (*setsockopt)(void *obj, int level, int optname,
1184 const void *optval, net_socklen_t optlen);
1185 ssize_t (*sendmsg)(void *obj, const struct net_msghdr *msg, int flags);
1186 ssize_t (*recvmsg)(void *obj, struct net_msghdr *msg, int flags);
1187 int (*getpeername)(void *obj, struct net_sockaddr *addr,
1188 net_socklen_t *addrlen);
1189 int (*getsockname)(void *obj, struct net_sockaddr *addr,
1190 net_socklen_t *addrlen);
1191 };
1192
1193 /** @endcond */
1194
1195 #ifdef __cplusplus
1196 }
1197 #endif
1198
1199 #include <zephyr/syscalls/socket.h>
1200
1201 /**
1202 * @}
1203 */
1204
1205 #endif /* ZEPHYR_INCLUDE_NET_SOCKET_H_ */
1206