Debian Codegraph @

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

raw
1 .\" Copyright 2020, Michael Kerrisk <[email protected]>
2 .\" Copyright, the authors of the Linux man-pages project
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH sockaddr 3type 2026-02-08 "Linux man-pages 6.18"
7 .SH NAME
8 sockaddr, sockaddr_storage, socklen_t
9 \- socket address
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc )
13 .SH SYNOPSIS
14 .EX
15 .B #include <sys/socket.h>
16 .P
17 .B struct sockaddr {
18 .BR " sa_family_t sa_family;" " /* Address family */"
19 .BR " char sa_data[];" " /* Socket address */"
20 .B };
21 .P
22 .B struct sockaddr_storage {
23 .BR " sa_family_t ss_family;" " /* Address family */"
24 .B };
25 .P
26 .BR typedef " /* ... */ " socklen_t;
27 .BR typedef " /* ... */ " sa_family_t;
28 .P
29 .EE
30 .SH DESCRIPTION
31 .TP
32 .I sockaddr
33 Describes a socket address.
34 .TP
35 .I sockaddr_storage
36 A structure at least as large as any other
37 .IR sockaddr_ *
38 address structures.
39 It's aligned so that a pointer to it can be cast
40 as a pointer to other
41 .IR sockaddr_ *
42 structures and used to access its fields.
43 .TP
44 .I socklen_t
45 Describes the length of a socket address.
46 This is an integer type of at least 32 bits.
47 .TP
48 .I sa_family_t
49 Describes a socket's protocol family.
50 This is an unsigned integer type.
51 .SS Internet domain sockets
52 See
53 .BR sockaddr_in (3type)
54 and
55 .BR sockaddr_in6 (3type).
56 .SS UNIX domain sockets
57 See
58 .BR sockaddr_un (3type).
59 .SH STANDARDS
60 POSIX.1-2024.
61 .SH HISTORY
62 POSIX.1-2001.
63 .P
64 .I socklen_t
65 was invented by POSIX.
66 See also
67 .BR accept (2).
68 .P
69 These structures were invented before modern ISO C strict-aliasing rules.
70 If aliasing rules are applied strictly,
71 these structures would be extremely difficult to use
72 without invoking undefined behavior.
73 POSIX.1-2024 fixed this
74 by requiring that implementations
75 make sure that these structures
76 can be safely used as they were designed.
77 .SH NOTES
78 .I socklen_t
79 is also defined in
80 .IR <netdb.h> .
81 .P
82 .I sa_family_t
83 is also defined in
84 .I <netinet/in.h>
85 and
86 .IR <sys/un.h> .
87 .SH SEE ALSO
88 .BR accept (2),
89 .BR bind (2),
90 .BR connect (2),
91 .BR getpeername (2),
92 .BR getsockname (2),
93 .BR getsockopt (2),
94 .BR sendto (2),
95 .BR setsockopt (2),
96 .BR socket (2),
97 .BR socketpair (2),
98 .BR getaddrinfo (3),
99 .BR gethostbyaddr (3),
100 .BR getnameinfo (3),
101 .BR htonl (3),
102 .BR ipv6 (7),
103 .BR socket (7)