posix-next API 0.1.0
Out-of-tree Zephyr POSIX module
Loading...
Searching...
No Matches
socket.h File Reference

POSIX socket API (<sys/socket.h>) More...

#include <stddef.h>
#include <sys/types.h>
#include <zephyr/net/net_ip.h>
#include <zephyr/net/socket.h>
#include <zephyr/sys/util.h>
Include dependency graph for socket.h:

Go to the source code of this file.

Data Structures

struct  sockaddr
 Generic socket address. More...
 
struct  sockaddr_storage
 Protocol-independent socket address storage. More...
 
struct  iovec
 Scatter/gather array element. More...
 
struct  msghdr
 Message header for sendmsg() and recvmsg(). More...
 
struct  cmsghdr
 Ancillary data object header. More...
 
struct  linger
 Socket linger option structure. More...
 

Macros

#define SCM_RIGHTS   1
 Access rights (file descriptors) in ancillary data.
 
#define CMSG_DATA(cmsg)   ((unsigned char *)(cmsg) + ROUND_UP(sizeof(struct cmsghdr), sizeof(size_t)))
 Pointer to ancillary data payload.
 
#define CMSG_NXTHDR(mhdr, cmsg)
 Next ancillary data object in a message.
 
#define CMSG_FIRSTHDR(mhdr)
 First ancillary data object in a message.
 
#define SOCK_DGRAM   NET_SOCK_DGRAM
 Datagram socket.
 
#define SOCK_RAW   NET_SOCK_RAW
 Raw socket.
 
#define SOCK_SEQPACKET   5
 Sequenced-packet socket.
 
#define SOCK_STREAM   NET_SOCK_STREAM
 Stream socket.
 
#define SOL_SOCKET   ZSOCK_SOL_SOCKET
 Socket-level option level for setsockopt() and getsockopt().
 
#define SO_ACCEPTCONN   ZSOCK_SO_ACCEPTCONN
 Socket is accepting connections.
 
#define SO_BROADCAST   ZSOCK_SO_BROADCAST
 Permit sending broadcast datagrams.
 
#define SO_DEBUG   ZSOCK_SO_DEBUG
 Record debugging information (ignored; for compatibility).
 
#define SO_DONTROUTE   ZSOCK_SO_DONTROUTE
 Bypass routing when sending (ignored; for compatibility).
 
#define SO_ERROR   ZSOCK_SO_ERROR
 Socket error status.
 
#define SO_KEEPALIVE   ZSOCK_SO_KEEPALIVE
 Keep connections alive.
 
#define SO_LINGER   ZSOCK_SO_LINGER
 Linger on close.
 
#define SO_OOBINLINE   ZSOCK_SO_OOBINLINE
 Deliver out-of-band data inline (ignored; for compatibility).
 
#define SO_RCVBUF   ZSOCK_SO_RCVBUF
 Receive buffer size.
 
#define SO_RCVLOWAT   ZSOCK_SO_RCVLOWAT
 Receive low watermark.
 
#define SO_RCVTIMEO   ZSOCK_SO_RCVTIMEO
 Receive timeout.
 
#define SO_REUSEADDR   ZSOCK_SO_REUSEADDR
 Allow local address reuse.
 
#define SO_SNDBUF   ZSOCK_SO_SNDBUF
 Send buffer size.
 
#define SO_SNDLOWAT   ZSOCK_SO_SNDLOWAT
 Send low watermark.
 
#define SO_SNDTIMEO   ZSOCK_SO_SNDTIMEO
 Send timeout.
 
#define SO_TYPE   ZSOCK_SO_TYPE
 Socket type.
 
#define SOMAXCONN   ZSOCK_SOMAXCONN
 Maximum pending connection queue length for listen().
 
#define MSG_CTRUNC   ZSOCK_MSG_CTRUNC
 Control data was truncated.
 
#define MSG_DONTROUTE   0x04
 Send without using routing tables.
 
#define MSG_EOR   0x80
 Terminates a record (if supported by the protocol).
 
#define MSG_OOB   0x01
 Out-of-band data.
 
#define MSG_NOSIGNAL   0x4000
 No SIGPIPE on send to a disconnected stream socket.
 
#define MSG_PEEK   ZSOCK_MSG_PEEK
 Peek at incoming data without consuming it.
 
#define MSG_TRUNC   ZSOCK_MSG_TRUNC
 Datagram was truncated.
 
#define MSG_WAITALL   ZSOCK_MSG_WAITALL
 Wait for a full request.
 
#define AF_UNSPEC   NET_AF_UNSPEC
 Unspecified address family.
 
#define AF_INET   NET_AF_INET
 Internet domain sockets for use with IPv4 addresses.
 
#define AF_INET6   NET_AF_INET6
 Internet domain sockets for use with IPv6 addresses.
 
#define AF_UNIX   NET_AF_UNIX
 UNIX domain sockets.
 
#define SHUT_RD   ZSOCK_SHUT_RD
 Disables further receive operations.
 
#define SHUT_WR   ZSOCK_SHUT_WR
 Disables further send operations.
 
#define SHUT_RDWR   ZSOCK_SHUT_RDWR
 Disables further send and receive operations.
 

Typedefs

typedef net_socklen_t socklen_t
 Type for socket address length values.
 
typedef net_sa_family_t sa_family_t
 Socket address family type.
 

Functions

int accept (int sock, struct sockaddr *addr, socklen_t *addrlen)
 Accept a new connection on a listening socket.
 
int bind (int sock, const struct sockaddr *addr, socklen_t addrlen)
 Assign a local address to a socket.
 
int connect (int sock, const struct sockaddr *addr, socklen_t addrlen)
 Initiate a connection on a socket.
 
int getpeername (int sock, struct sockaddr *addr, socklen_t *addrlen)
 Get the address of the peer connected to a socket.
 
int getsockname (int sock, struct sockaddr *addr, socklen_t *addrlen)
 Get the local address bound to a socket.
 
int getsockopt (int sock, int level, int optname, void *optval, socklen_t *optlen)
 Get socket options.
 
int listen (int sock, int backlog)
 Mark a socket as passive (ready to accept connections).
 
ssize_t recv (int sock, void *buf, size_t max_len, int flags)
 Receive data from a connected socket.
 
ssize_t recvfrom (int sock, void *buf, size_t max_len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
 Receive data and the sender's address from a socket.
 
ssize_t recvmsg (int sock, struct msghdr *msg, int flags)
 Receive a message (with scatter-gather I/O and ancillary data).
 
ssize_t send (int sock, const void *buf, size_t len, int flags)
 Send data on a connected socket.
 
ssize_t sendmsg (int sock, const struct msghdr *message, int flags)
 Send a message (with scatter-gather I/O and ancillary data).
 
ssize_t sendto (int sock, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
 Send data to a specific destination address.
 
int setsockopt (int sock, int level, int optname, const void *optval, socklen_t optlen)
 Set socket options.
 
int shutdown (int sock, int how)
 Shut down part or all of a full-duplex connection.
 
int sockatmark (int s)
 Determine whether a socket is at the out-of-band mark.
 
int socket (int family, int type, int proto)
 Create a new socket.
 
int socketpair (int family, int type, int proto, int sv[2])
 Create a pair of connected sockets.
 

Detailed Description

POSIX socket API (<sys/socket.h>)

See also
POSIX.1-2017 <sys/socket.h>

Definition in file socket.h.

Macro Definition Documentation

◆ AF_INET

#define AF_INET   NET_AF_INET

Internet domain sockets for use with IPv4 addresses.

Definition at line 199 of file socket.h.

◆ AF_INET6

#define AF_INET6   NET_AF_INET6

Internet domain sockets for use with IPv6 addresses.

Definition at line 201 of file socket.h.

◆ AF_UNIX

#define AF_UNIX   NET_AF_UNIX

UNIX domain sockets.

Definition at line 203 of file socket.h.

◆ AF_UNSPEC

#define AF_UNSPEC   NET_AF_UNSPEC

Unspecified address family.

Definition at line 197 of file socket.h.

◆ CMSG_DATA

#define CMSG_DATA (   cmsg)    ((unsigned char *)(cmsg) + ROUND_UP(sizeof(struct cmsghdr), sizeof(size_t)))

Pointer to ancillary data payload.

Definition at line 105 of file socket.h.

◆ CMSG_FIRSTHDR

#define CMSG_FIRSTHDR (   mhdr)
Value:
(((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
(struct cmsghdr *)((mhdr)->msg_control) : NULL))
Ancillary data object header.
Definition socket.h:91

First ancillary data object in a message.

Definition at line 117 of file socket.h.

◆ CMSG_NXTHDR

#define CMSG_NXTHDR (   mhdr,
  cmsg 
)
Value:
(((cmsg) == NULL) ? CMSG_FIRSTHDR(mhdr) : \
(((unsigned char *)(cmsg) + ROUND_UP((cmsg)->cmsg_len, sizeof(size_t)) + \
ROUND_UP(sizeof(struct cmsghdr), sizeof(size_t)) > \
(unsigned char *)((mhdr)->msg_control) + (mhdr)->msg_controllen) ? \
NULL : \
(struct cmsghdr *)((unsigned char *)(cmsg) + ROUND_UP((cmsg)->cmsg_len, sizeof(size_t)))))
#define CMSG_FIRSTHDR(mhdr)
First ancillary data object in a message.
Definition socket.h:117

Next ancillary data object in a message.

Definition at line 108 of file socket.h.

◆ MSG_CTRUNC

#define MSG_CTRUNC   ZSOCK_MSG_CTRUNC

Control data was truncated.

Definition at line 180 of file socket.h.

◆ MSG_DONTROUTE

#define MSG_DONTROUTE   0x04

Send without using routing tables.

Definition at line 182 of file socket.h.

◆ MSG_EOR

#define MSG_EOR   0x80

Terminates a record (if supported by the protocol).

Definition at line 184 of file socket.h.

◆ MSG_NOSIGNAL

#define MSG_NOSIGNAL   0x4000

No SIGPIPE on send to a disconnected stream socket.

Definition at line 188 of file socket.h.

◆ MSG_OOB

#define MSG_OOB   0x01

Out-of-band data.

Definition at line 186 of file socket.h.

◆ MSG_PEEK

#define MSG_PEEK   ZSOCK_MSG_PEEK

Peek at incoming data without consuming it.

Definition at line 190 of file socket.h.

◆ MSG_TRUNC

#define MSG_TRUNC   ZSOCK_MSG_TRUNC

Datagram was truncated.

Definition at line 192 of file socket.h.

◆ MSG_WAITALL

#define MSG_WAITALL   ZSOCK_MSG_WAITALL

Wait for a full request.

Definition at line 194 of file socket.h.

◆ SCM_RIGHTS

#define SCM_RIGHTS   1

Access rights (file descriptors) in ancillary data.

Definition at line 101 of file socket.h.

◆ SHUT_RD

#define SHUT_RD   ZSOCK_SHUT_RD

Disables further receive operations.

Definition at line 206 of file socket.h.

◆ SHUT_RDWR

#define SHUT_RDWR   ZSOCK_SHUT_RDWR

Disables further send and receive operations.

Definition at line 210 of file socket.h.

◆ SHUT_WR

#define SHUT_WR   ZSOCK_SHUT_WR

Disables further send operations.

Definition at line 208 of file socket.h.

◆ SO_ACCEPTCONN

#define SO_ACCEPTCONN   ZSOCK_SO_ACCEPTCONN

Socket is accepting connections.

Definition at line 144 of file socket.h.

◆ SO_BROADCAST

#define SO_BROADCAST   ZSOCK_SO_BROADCAST

Permit sending broadcast datagrams.

Definition at line 146 of file socket.h.

◆ SO_DEBUG

#define SO_DEBUG   ZSOCK_SO_DEBUG

Record debugging information (ignored; for compatibility).

Definition at line 148 of file socket.h.

◆ SO_DONTROUTE

#define SO_DONTROUTE   ZSOCK_SO_DONTROUTE

Bypass routing when sending (ignored; for compatibility).

Definition at line 150 of file socket.h.

◆ SO_ERROR

#define SO_ERROR   ZSOCK_SO_ERROR

Socket error status.

Definition at line 152 of file socket.h.

◆ SO_KEEPALIVE

#define SO_KEEPALIVE   ZSOCK_SO_KEEPALIVE

Keep connections alive.

Definition at line 154 of file socket.h.

◆ SO_LINGER

#define SO_LINGER   ZSOCK_SO_LINGER

Linger on close.

Definition at line 156 of file socket.h.

◆ SO_OOBINLINE

#define SO_OOBINLINE   ZSOCK_SO_OOBINLINE

Deliver out-of-band data inline (ignored; for compatibility).

Definition at line 158 of file socket.h.

◆ SO_RCVBUF

#define SO_RCVBUF   ZSOCK_SO_RCVBUF

Receive buffer size.

Definition at line 160 of file socket.h.

◆ SO_RCVLOWAT

#define SO_RCVLOWAT   ZSOCK_SO_RCVLOWAT

Receive low watermark.

Definition at line 162 of file socket.h.

◆ SO_RCVTIMEO

#define SO_RCVTIMEO   ZSOCK_SO_RCVTIMEO

Receive timeout.

Definition at line 164 of file socket.h.

◆ SO_REUSEADDR

#define SO_REUSEADDR   ZSOCK_SO_REUSEADDR

Allow local address reuse.

Definition at line 166 of file socket.h.

◆ SO_SNDBUF

#define SO_SNDBUF   ZSOCK_SO_SNDBUF

Send buffer size.

Definition at line 168 of file socket.h.

◆ SO_SNDLOWAT

#define SO_SNDLOWAT   ZSOCK_SO_SNDLOWAT

Send low watermark.

Definition at line 170 of file socket.h.

◆ SO_SNDTIMEO

#define SO_SNDTIMEO   ZSOCK_SO_SNDTIMEO

Send timeout.

Definition at line 172 of file socket.h.

◆ SO_TYPE

#define SO_TYPE   ZSOCK_SO_TYPE

Socket type.

Definition at line 174 of file socket.h.

◆ SOCK_DGRAM

#define SOCK_DGRAM   NET_SOCK_DGRAM

Datagram socket.

Definition at line 132 of file socket.h.

◆ SOCK_RAW

#define SOCK_RAW   NET_SOCK_RAW

Raw socket.

Definition at line 134 of file socket.h.

◆ SOCK_SEQPACKET

#define SOCK_SEQPACKET   5

Sequenced-packet socket.

Definition at line 136 of file socket.h.

◆ SOCK_STREAM

#define SOCK_STREAM   NET_SOCK_STREAM

Stream socket.

Definition at line 138 of file socket.h.

◆ SOL_SOCKET

#define SOL_SOCKET   ZSOCK_SOL_SOCKET

Socket-level option level for setsockopt() and getsockopt().

Definition at line 141 of file socket.h.

◆ SOMAXCONN

#define SOMAXCONN   ZSOCK_SOMAXCONN

Maximum pending connection queue length for listen().

Definition at line 177 of file socket.h.

Typedef Documentation

◆ sa_family_t

typedef net_sa_family_t sa_family_t

Socket address family type.

Definition at line 39 of file socket.h.

◆ socklen_t

typedef net_socklen_t socklen_t

Type for socket address length values.

Definition at line 32 of file socket.h.