| sockaddr(3type) | sockaddr(3type) |
sockaddr, sockaddr_storage, sockaddr_in, sockaddr_in6, sockaddr_un, socklen_t, in_addr, in6_addr, in_addr_t, in_port_t, - socket address
Standard C library (libc)
#include <sys/socket.h>
struct sockaddr {
sa_family_t sa_family; /* Address family */
char sa_data[]; /* Socket address */
};
struct sockaddr_storage {
sa_family_t ss_family; /* Address family */
};
typedef /* ... */ socklen_t; typedef /* ... */ sa_family_t;
#include <netinet/in.h>
struct sockaddr_in {
sa_family_t sin_family; /* AF_INET */
in_port_t sin_port; /* Port number */
struct in_addr sin_addr; /* IPv4 address */
};
struct sockaddr_in6 {
sa_family_t sin6_family; /* AF_INET6 */
in_port_t sin6_port; /* Port number */
uint32_t sin6_flowinfo; /* IPv6 flow info */
struct in6_addr sin6_addr; /* IPv6 address */
uint32_t sin6_scope_id; /* Set of interfaces for a scope */
};
struct in_addr {
in_addr_t s_addr;
};
struct in6_addr {
uint8_t s6_addr[16];
};
typedef uint32_t in_addr_t; typedef uint16_t in_port_t;
#include <sys/un.h>
struct sockaddr_un {
sa_family_t sun_family; /* Address family */
char sun_path[]; /* Socket pathname */
};
POSIX.1-2008.
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.
socklen_t is also defined in <netdb.h>.
sa_family_t is also defined in <netinet/in.h> and <sys/un.h>.
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)
| 2023-10-31 | Linux man-pages 6.7 |