Debian Codegraph @

upstream/debian-trixie/man3/sockaddr.3type

raw
1 .\" Copyright (c) 2020-2022 by Alejandro Colomar <[email protected]>
2 .\" and Copyright (c) 2020 by Michael Kerrisk <[email protected]>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .\"
7 .TH sockaddr 3type 2024-05-02 "Linux man-pages 6.9.1"
8 .SH NAME
9 sockaddr, sockaddr_storage, sockaddr_in, sockaddr_in6, sockaddr_un, socklen_t,
10 in_addr, in6_addr, in_addr_t, in_port_t,
11 \- socket address
12 .SH LIBRARY
13 Standard C library
14 .RI ( libc )
15 .SH SYNOPSIS
16 .EX
17 .B #include <sys/socket.h>
18 .P
19 .B struct sockaddr {
20 .BR " sa_family_t sa_family;" " /* Address family */"
21 .BR " char sa_data[];" " /* Socket address */"
22 .B };
23 .P
24 .B struct sockaddr_storage {
25 .BR " sa_family_t ss_family;" " /* Address family */"
26 .B };
27 .P
28 .BR typedef " /* ... */ " socklen_t;
29 .BR typedef " /* ... */ " sa_family_t;
30 .P
31 .EE
32 .SS Internet domain sockets
33 .EX
34 .B #include <netinet/in.h>
35 .P
36 .B struct sockaddr_in {
37 .BR " sa_family_t sin_family;" " /* " AF_INET " */"
38 .BR " in_port_t sin_port;" " /* Port number */"
39 .BR " struct in_addr sin_addr;" " /* IPv4 address */"
40 .B };
41 .P
42 .B struct sockaddr_in6 {
43 .BR " sa_family_t sin6_family;" " /* " AF_INET6 " */"
44 .BR " in_port_t sin6_port;" " /* Port number */"
45 .BR " uint32_t sin6_flowinfo;" " /* IPv6 flow info */"
46 .BR " struct in6_addr sin6_addr;" " /* IPv6 address */"
47 .BR " uint32_t sin6_scope_id;" " /* Set of interfaces for a scope */"
48 .B };
49 .P
50 .B struct in_addr {
51 .B " in_addr_t s_addr;"
52 .B };
53 .P
54 .B struct in6_addr {
55 .B " uint8_t s6_addr[16];"
56 .B };
57 .P
58 .B typedef uint32_t in_addr_t;
59 .B typedef uint16_t in_port_t;
60 .EE
61 .SS UNIX domain sockets
62 .EX
63 .B #include <sys/un.h>
64 .P
65 .B struct sockaddr_un {
66 .BR " sa_family_t sun_family;" " /* Address family */"
67 .BR " char sun_path[];" " /* Socket pathname */"
68 .B };
69 .EE
70 .SH DESCRIPTION
71 .TP
72 .I sockaddr
73 Describes a socket address.
74 .TP
75 .I sockaddr_storage
76 A structure at least as large as any other
77 .IR sockaddr_ *
78 address structures.
79 It's aligned so that a pointer to it can be cast
80 as a pointer to other
81 .IR sockaddr_ *
82 structures and used to access its fields.
83 .TP
84 .I socklen_t
85 Describes the length of a socket address.
86 This is an integer type of at least 32 bits.
87 .TP
88 .I sa_family_t
89 Describes a socket's protocol family.
90 This is an unsigned integer type.
91 .SS Internet domain sockets
92 .TP
93 .I sockaddr_in
94 Describes an IPv4 Internet domain socket address.
95 The
96 .I sin_port
97 and
98 .I sin_addr
99 members are stored in network byte order.
100 .TP
101 .I sockaddr_in6
102 Describes an IPv6 Internet domain socket address.
103 The
104 .I sin6_addr.s6_addr
105 array is used to contain a 128-bit IPv6 address,
106 stored in network byte order.
107 .SS UNIX domain sockets
108 .TP
109 .I sockaddr_un
110 Describes a UNIX domain socket address.
111 .SH STANDARDS
112 POSIX.1-2008.
113 .SH HISTORY
114 POSIX.1-2001.
115 .P
116 .I socklen_t
117 was invented by POSIX.
118 See also
119 .BR accept (2).
120 .P
121 These structures were invented before modern ISO C strict-aliasing rules.
122 If aliasing rules are applied strictly,
123 these structures would be extremely difficult to use
124 without invoking Undefined Behavior.
125 POSIX Issue 8 will fix this by requiring that implementations
126 make sure that these structures
127 can be safely used as they were designed.
128 .SH NOTES
129 .I socklen_t
130 is also defined in
131 .IR <netdb.h> .
132 .P
133 .I sa_family_t
134 is also defined in
135 .I <netinet/in.h>
136 and
137 .IR <sys/un.h> .
138 .SH SEE ALSO
139 .BR accept (2),
140 .BR bind (2),
141 .BR connect (2),
142 .BR getpeername (2),
143 .BR getsockname (2),
144 .BR getsockopt (2),
145 .BR sendto (2),
146 .BR setsockopt (2),
147 .BR socket (2),
148 .BR socketpair (2),
149 .BR getaddrinfo (3),
150 .BR gethostbyaddr (3),
151 .BR getnameinfo (3),
152 .BR htonl (3),
153 .BR ipv6 (7),
154 .BR socket (7)