1sockaddr(3type)                                                sockaddr(3type)
2
3
4

NAME

6       sockaddr,  sockaddr_storage,  sockaddr_in,  sockaddr_in6,  sockaddr_un,
7       socklen_t, in_addr, in6_addr, in_addr_t, in_port_t, - socket address
8

LIBRARY

10       Standard C library (libc)
11

SYNOPSIS

13       #include <sys/socket.h>
14
15       struct sockaddr {
16           sa_family_t     sa_family;      /* Address family */
17           char            sa_data[];      /* Socket address */
18       };
19
20       struct sockaddr_storage {
21           sa_family_t     ss_family;      /* Address family */
22       };
23
24       typedef /* ... */ socklen_t;
25       typedef /* ... */ sa_family_t;
26
27   Internet domain sockets
28       #include <netinet/in.h>
29
30       struct sockaddr_in {
31           sa_family_t     sin_family;     /* AF_INET */
32           in_port_t       sin_port;       /* Port number */
33           struct in_addr  sin_addr;       /* IPv4 address */
34       };
35
36       struct sockaddr_in6 {
37           sa_family_t     sin6_family;    /* AF_INET6 */
38           in_port_t       sin6_port;      /* Port number */
39           uint32_t        sin6_flowinfo;  /* IPv6 flow info */
40           struct in6_addr sin6_addr;      /* IPv6 address */
41           uint32_t        sin6_scope_id;  /* Set of interfaces for a scope */
42       };
43
44       struct in_addr {
45           in_addr_t s_addr;
46       };
47
48       struct in6_addr {
49           uint8_t   s6_addr[16];
50       };
51
52       typedef uint32_t in_addr_t;
53       typedef uint16_t in_port_t;
54
55   UNIX domain sockets
56       #include <sys/un.h>
57
58       struct sockaddr_un {
59           sa_family_t     sun_family;     /* Address family */
60           char            sun_path[];     /* Socket pathname */
61       };
62

DESCRIPTION

64       sockaddr
65              Describes a socket address.
66
67       sockaddr_storage
68              A structure at least as large as any  other  sockaddr_*  address
69              structures.  It's aligned so that a pointer to it can be cast as
70              a pointer to other sockaddr_* structures and used to access  its
71              fields.
72
73       socklen_t
74              Describes  the  length  of a socket address.  This is an integer
75              type of at least 32 bits.
76
77       sa_family_t
78              Describes a socket's protocol family.  This is an unsigned inte‐
79              ger type.
80
81   Internet domain sockets
82       sockaddr_in
83              Describes  an IPv4 Internet domain socket address.  The sin_port
84              and sin_addr members are stored in network byte order.
85
86       sockaddr_in6
87              Describes  an  IPv6  Internet  domain   socket   address.    The
88              sin6_addr.s6_addr  array  is  used to contain a 128-bit IPv6 ad‐
89              dress, stored in network byte order.
90
91   UNIX domain sockets
92       sockaddr_un
93              Describes a UNIX domain socket address.
94

STANDARDS

96       POSIX.1-2008.
97

HISTORY

99       POSIX.1-2001.
100
101       socklen_t was invented by POSIX.  See also accept(2).
102
103       These structures were invented  before  modern  ISO  C  strict-aliasing
104       rules.   If aliasing rules are applied strictly, these structures would
105       be extremely difficult to  use  without  invoking  Undefined  Behavior.
106       POSIX Issue 8 will fix this by requiring that implementations make sure
107       that these structures can be safely used as they were designed.
108

NOTES

110       socklen_t is also defined in <netdb.h>.
111
112       sa_family_t is also defined in <netinet/in.h> and <sys/un.h>.
113

SEE ALSO

115       accept(2), bind(2), connect(2),  getpeername(2),  getsockname(2),  get‐
116       sockopt(2),  sendto(2), setsockopt(2), socket(2), socketpair(2), getad‐
117       drinfo(3),   gethostbyaddr(3),   getnameinfo(3),   htonl(3),   ipv6(7),
118       socket(7)
119
120
121
122Linux man-pages 6.05              2023-04-22                   sockaddr(3type)
Impressum