sockaddr, sockaddr_storage, sockaddr_in, sockaddr_in6, sockaddr_un, socklen_t, in_addr, in6_addr,
Contents
Description
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.
Internetdomainsocketssockaddr_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.
UNIXdomainsocketssockaddr_un
Describes a UNIX domain socket address.
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.
Library
Standard C library (libc)
Name
sockaddr, sockaddr_storage, sockaddr_in, sockaddr_in6, sockaddr_un, socklen_t, in_addr, in6_addr,
in_addr_t, in_port_t, - socket address
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) Linux man-pages 6.9.1 2024-05-02 sockaddr(3type)
Standards
POSIX.1-2008.
Synopsis
#include<sys/socket.h>structsockaddr{sa_family_tsa_family; /* Address family */
charsa_data[]; /* Socket address */
};structsockaddr_storage{sa_family_tss_family; /* Address family */
};typedef /* ... */ socklen_t;typedef /* ... */ sa_family_t;Internetdomainsockets#include<netinet/in.h>structsockaddr_in{sa_family_tsin_family; /* AF_INET */
in_port_tsin_port; /* Port number */
structin_addrsin_addr; /* IPv4 address */
};structsockaddr_in6{sa_family_tsin6_family; /* AF_INET6 */
in_port_tsin6_port; /* Port number */
uint32_tsin6_flowinfo; /* IPv6 flow info */
structin6_addrsin6_addr; /* IPv6 address */
uint32_tsin6_scope_id; /* Set of interfaces for a scope */
};structin_addr{in_addr_ts_addr;};structin6_addr{uint8_ts6_addr[16];};typedefuint32_tin_addr_t;typedefuint16_tin_port_t;UNIXdomainsockets#include<sys/un.h>structsockaddr_un{sa_family_tsun_family; /* Address family */
charsun_path[]; /* Socket pathname */
};