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