| sockaddr | Describes a socket address. |
| sockaddr_storage | A structure at least as large as any other sockaddr_* address structures. It's aligned so that a pointer to it can be cast as a pointer to other sockaddr_* structures and used to access its fields. |
| socklen_t | Describes the length of a socket address. This is an integer type of at least 32 bits. |
| sa_family_t | Describes a socket's protocol family. This is an unsigned integer type. |
| sockaddr_in | Describes an IPv4 Internet domain socket address. The sin_port and sin_addr members are stored in network byte order. |
| sockaddr_in6 | Describes an IPv6 Internet domain socket address. The sin6_addr.s6_addr array is used to contain a 128-bit IPv6 address, stored in network byte order. |
| sockaddr_un | Describes a UNIX domain socket address. |
NAME
sockaddr, sockaddr_storage, sockaddr_in, sockaddr_in6, sockaddr_un, socklen_t, in_addr, in6_addr, in_addr_t, in_port_t, - socket address
LIBRARY
Standard C library (libc)
SYNOPSIS
#include <sys/socket.h>struct sockaddr {\n
\n sa_family_t sa_family;\n /* Address family */
\n char sa_data[];\n /* Socket address */
\n};struct sockaddr_storage {\n
\n sa_family_t ss_family;\n /* Address family */
\n};typedef\n /* ... */ \nsocklen_t;\n
\ntypedef\n /* ... */ \nsa_family_t;Internet domain sockets
#include <netinet/in.h>struct sockaddr_in {\n
\n sa_family_t sin_family;\n /* \nAF_INET\n */
\n in_port_t sin_port;\n /* Port number */
\n struct in_addr sin_addr;\n /* IPv4 address */
\n};struct sockaddr_in6 {\n
\n sa_family_t sin6_family;\n /* \nAF_INET6\n */
\n in_port_t sin6_port;\n /* Port number */
\n uint32_t sin6_flowinfo;\n /* IPv6 flow info */
\n struct in6_addr sin6_addr;\n /* IPv6 address */
\n uint32_t sin6_scope_id;\n /* Set of interfaces for a scope */
\n};struct in_addr {\n
\n in_addr_t s_addr;\n
\n};struct in6_addr {\n
\n uint8_t s6_addr[16];\n
\n};typedef uint32_t in_addr_t;\n
\ntypedef uint16_t in_port_t;\nUNIX domain sockets
#include <sys/un.h>struct sockaddr_un {\n
\n sa_family_t sun_family;\n /* Address family */
\n char sun_path[];\n /* Socket pathname */
\n};\nDESCRIPTION
- sockaddr
Describes a socket address.
- sockaddr_storage
A structure at least as large as any other sockaddr_* address structures. It's aligned so that a pointer to it can be cast as a pointer to other sockaddr_* structures and used to access its fields.
- socklen_t
Describes the length of a socket address. This is an integer type of at least 32 bits.
- sa_family_t
Describes a socket's protocol family. This is an unsigned integer type.
Internet domain sockets
- sockaddr_in
Describes an IPv4 Internet domain socket address. The sin_port and sin_addr members are stored in network byte order.
- sockaddr_in6
Describes an IPv6 Internet domain socket address. The sin6_addr.s6_addr array is used to contain a 128-bit IPv6 address, stored in network byte order.
UNIX domain sockets
- sockaddr_un
Describes a UNIX domain socket address.
STANDARDS
POSIX.1-2008.
HISTORY
POSIX.1-2001.
socklen_t was invented by POSIX. See also accept(2).
These structures were invented before modern ISO C strict-aliasing rules. If aliasing rules are applied strictly, these structures would be extremely difficult to use without invoking Undefined Behavior. POSIX Issue 8 will fix this by requiring that implementations make sure that these structures can be safely used as they were designed.
NOTES
socklen_t is also defined in <netdb.h>.
sa_family_t is also defined in <netinet/in.h> and <sys/un.h>.
SEE ALSO
accept(2), bind(2), connect(2), getpeername(2), getsockname(2), getsockopt(2), sendto(2), setsockopt(2), socket(2), socketpair(2), getaddrinfo(3), gethostbyaddr(3), getnameinfo(3), htonl(3), ipv6(7), socket(7)