summaryrefslogtreecommitdiffstats
path: root/man-pages-posix-2017/man0p/netinet_in.h.0p
blob: 9f9c50aa809cb13002336a5a72c2521624874013 (plain) (blame)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
'\" et
.TH netinet_in.h "0P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.\"
.SH NAME
netinet/in.h
\(em Internet address family
.SH SYNOPSIS
.LP
.nf
#include <netinet/in.h>
.fi
.SH DESCRIPTION
The
.IR <netinet/in.h> 
header shall define the following types:
.IP "\fBin_port_t\fP" 10
Equivalent to the type
.BR uint16_t
as described in
.IR <inttypes.h> .
.IP "\fBin_addr_t\fP" 10
Equivalent to the type
.BR uint32_t
as described in
.IR <inttypes.h> .
.P
The
.IR <netinet_in.h> 
header shall define the
.BR sa_family_t
type as described in
.IR <sys/socket.h> .
.P
The
.IR <netinet_in.h> 
header shall define the
.BR uint8_t
and
.BR uint32_t
types as described in
.IR <inttypes.h> .
Inclusion of the
.IR <netinet/in.h> 
header may also make visible all symbols from
.IR <inttypes.h> 
and
.IR <sys/socket.h> .
.P
The
.IR <netinet/in.h> 
header shall define the
.BR in_addr
structure, which shall include at least the following member:
.sp
.RS 4
.nf

in_addr_t  s_addr
.fi
.P
.RE
.P
The
.IR <netinet/in.h> 
header shall define the
.BR sockaddr_in
structure, which shall include at least the following members:
.sp
.RS 4
.nf

sa_family_t     sin_family   \fRAF_INET.\fR
in_port_t       sin_port     \fRPort number.\fR
struct in_addr  sin_addr     \fRIP address.\fR
.fi
.P
.RE
.P
The
.IR sin_port
and
.IR sin_addr
members shall be in network byte order.
.P
The
.BR sockaddr_in
structure is used to store addresses for the Internet address family.
Pointers to this type shall be cast by applications to
.BR "struct sockaddr *"
for use with socket functions.
.P
The
.IR <netinet/in.h> 
header shall define the
.BR in6_addr
structure, which shall include at least the following member:
.sp
.RS 4
.nf

uint8_t s6_addr[16]
.fi
.P
.RE
.P
This array is used to contain a 128-bit IPv6 address, stored in network
byte order.
.P
The
.IR <netinet/in.h> 
header shall define the
.BR sockaddr_in6
structure, which shall include at least the following members:
.sp
.RS 4
.nf

sa_family_t      sin6_family    \fRAF_INET6.\fR
in_port_t        sin6_port      \fRPort number.\fR
uint32_t         sin6_flowinfo  \fRIPv6 traffic class and flow information.\fR
struct in6_addr  sin6_addr      \fRIPv6 address.\fR
uint32_t         sin6_scope_id  \fRSet of interfaces for a scope.\fR
.fi
.P
.RE
.P
The
.IR sin6_port
and
.IR sin6_addr
members shall be in network byte order.
.P
Prior to calling a function in this standard which reads values from a
.BR sockaddr_in6
structure (for example,
\fIbind\fR()
or
\fIconnect\fR()),
the application shall ensure that all members of the structure,
including any additional non-standard members, if any, are initialized.
If the
.BR sockaddr_in6
structure has a non-standard member, and that member has a value
other than the value that would result from default initialization,
the behavior of any function in this standard that reads values
from the
.BR sockaddr_in6
structure is implementation-defined. All functions in this standard
that return data in a
.BR sockaddr_in6
structure (for example,
\fIgetaddrinfo\fR()
or
\fIaccept\fR())
shall initialize the structure in a way that meets the above
requirements, and shall ensure that each non-standard member,
if any, has a value that produces the same behavior as default
initialization would in all functions in this standard which
read values from a
.BR sockaddr_in6
structure.
.P
The
.IR sin6_scope_id
field is a 32-bit integer that identifies a set of interfaces as
appropriate for the scope of the address carried in the
.IR sin6_addr
field. For a link scope
.IR sin6_addr ,
the application shall ensure that
.IR sin6_scope_id
is a link index. For a site scope
.IR sin6_addr ,
the application shall ensure that
.IR sin6_scope_id
is a site index. The mapping of
.IR sin6_scope_id
to an interface or set of interfaces is implementation-defined.
.P
The
.IR <netinet/in.h> 
header shall declare the following external variable:
.sp
.RS 4
.nf

const struct in6_addr in6addr_any
.fi
.P
.RE
.P
This variable is initialized by the system to contain the wildcard IPv6
address. The
.IR <netinet/in.h> 
header also defines the IN6ADDR_ANY_INIT macro. This macro must be
constant at compile time and can be used to initialize a variable of
type
.BR "struct in6_addr"
to the IPv6 wildcard address.
.P
The
.IR <netinet/in.h> 
header shall declare the following external variable:
.sp
.RS 4
.nf

const struct in6_addr in6addr_loopback
.fi
.P
.RE
.P
This variable is initialized by the system to contain the loopback IPv6
address. The
.IR <netinet/in.h> 
header also defines the IN6ADDR_LOOPBACK_INIT macro. This macro must be
constant at compile time and can be used to initialize a variable of
type
.BR "struct in6_addr"
to the IPv6 loopback address.
.P
The
.IR <netinet/in.h> 
header shall define the
.BR ipv6_mreq
structure, which shall include at least the following members:
.sp
.RS 4
.nf

struct in6_addr  ipv6mr_multiaddr  \fRIPv6 multicast address.\fR
unsigned         ipv6mr_interface  \fRInterface index.\fR
.fi
.P
.RE
.P
The
.IR <netinet/in.h> 
header shall define the following symbolic constants for use as
values of the
.IR level
argument of
\fIgetsockopt\fR()
and
\fIsetsockopt\fR():
.IP IPPROTO_IP 16
Internet protocol.
.IP IPPROTO_IPV6 16
Internet Protocol Version 6.
.IP IPPROTO_ICMP 16
Control message protocol.
.IP IPPROTO_RAW 16
Raw IP Packets Protocol.
.IP IPPROTO_TCP 16
Transmission control protocol.
.IP IPPROTO_UDP 16
User datagram protocol.
.P
The
.IR <netinet/in.h> 
header shall define the following symbolic constant for use as a
local address in the structure passed to
\fIbind\fR():
.IP INADDR_ANY 16
IPv4 wildcard address.
.P
The
.IR <netinet/in.h> 
header shall define the following symbolic constant for use as a
destination address in the structures passed to
\fIconnect\fR(),
\fIsendmsg\fR(),
and
\fIsendto\fR():
.IP INADDR_BROADCAST 16
IPv4 broadcast address.
.P
The
.IR <netinet/in.h> 
header shall define the following symbolic constant, with the value
specified, to help applications declare buffers of the proper size
to store IPv4 addresses in string form:
.IP INET_ADDRSTRLEN 16
16. Length of the string form for IP.
.P
The
\fIhtonl\fR(),
\fIhtons\fR(),
\fIntohl\fR(),
and
\fIntohs\fR()
functions shall be available as described in
.IR <arpa/inet.h> .
Inclusion of the
.IR <netinet/in.h> 
header may also make visible all symbols from
.IR <arpa/inet.h> .
.P
The
.IR <netinet/in.h> 
header shall define the following symbolic constant, with the value
specified, to help applications declare buffers of the proper size
to store IPv6 addresses in string form:
.IP INET6_ADDRSTRLEN 16
46. Length of the string form for IPv6.
.br
.P
The
.IR <netinet/in.h> 
header shall define the following symbolic constants, with distinct
integer values, for use in the
.IR option_name
argument in the
\fIgetsockopt\fR()
or
\fIsetsockopt\fR()
functions at protocol level IPPROTO_IPV6:
.IP IPV6_JOIN_GROUP 16
Join a multicast group.
.IP IPV6_LEAVE_GROUP 16
Quit a multicast group.
.IP IPV6_MULTICAST_HOPS 16
.br
Multicast hop limit.
.IP IPV6_MULTICAST_IF 16
Interface to use for outgoing multicast packets.
.IP IPV6_MULTICAST_LOOP 16
.br
Multicast packets are delivered back to the local application.
.IP IPV6_UNICAST_HOPS 16
Unicast hop limit.
.IP IPV6_V6ONLY 16
Restrict AF_INET6 socket to IPv6 communications only.
.P
The
.IR <netinet/in.h> 
header shall define the following macros that test for special IPv6
addresses. Each macro is of type
.BR int
and takes a single argument of type
.BR "const struct in6_addr *" :
.IP IN6_IS_ADDR_UNSPECIFIED 6
.br
Unspecified address.
.IP IN6_IS_ADDR_LOOPBACK 6
.br
Loopback address.
.IP IN6_IS_ADDR_MULTICAST 6
.br
Multicast address.
.IP IN6_IS_ADDR_LINKLOCAL 6
.br
Unicast link-local address.
.IP IN6_IS_ADDR_SITELOCAL 6
.br
Unicast site-local address.
.IP IN6_IS_ADDR_V4MAPPED 6
.br
IPv4 mapped address.
.IP IN6_IS_ADDR_V4COMPAT 6
.br
IPv4-compatible address.
.IP IN6_IS_ADDR_MC_NODELOCAL 6
.br
Multicast node-local address.
.IP IN6_IS_ADDR_MC_LINKLOCAL 6
.br
Multicast link-local address.
.IP IN6_IS_ADDR_MC_SITELOCAL 6
.br
Multicast site-local address.
.IP IN6_IS_ADDR_MC_ORGLOCAL 6
.br
Multicast organization-local address.
.IP IN6_IS_ADDR_MC_GLOBAL 6
.br
Multicast global address.
.LP
.IR "The following sections are informative."
.SH "APPLICATION USAGE"
Although applications are required to initialize all members
(including any non-standard ones) of a
.BR sockaddr_in6
structure, the same is not required for the
.BR sockaddr_in
structure, since historically many applications only initialized
the standard members. Despite this, applications are encouraged
to initialize
.BR sockaddr_in
structures in a manner similar to the required initialization of
.BR sockaddr_in6
structures.
.P
Although it is common practice to initialize a
.BR sockaddr_in6
structure using:
.sp
.RS 4
.nf

struct sockaddr_in6 sa;
memset(&sa, 0, sizeof sa);
.fi
.P
.RE
.P
this method is not portable according to this standard, because the
structure can contain pointer or floating-point members that are
not required to have an all-bits-zero representation after default
initialization. Portable methods make use of default initialization;
for example:
.sp
.RS 4
.nf

struct sockaddr_in6 sa = { 0 };
.fi
.P
.RE
.P
or:
.sp
.RS 4
.nf

static struct sockaddr_in6 sa_init;
struct sockaddr_in6 sa = sa_init;
.fi
.P
.RE
.P
A future version of this standard may require that a pointer object
with an all-bits-zero representation is a null pointer, and that
.BR sockaddr_in6
does not have any floating-point members if a floating-point object
with an all-bits-zero representation does not have the value 0.0.
.SH "RATIONALE"
The INADDR_ANY and INADDR_BROADCAST values are byte-order-neutral
and thus their byte order is not specified. Many implementations
have additional constants as extensions, such as INADDR_LOOPBACK,
that are not byte-order-neutral. Traditionally, these constants
are in host byte order, requiring the use of
\fIhtonl\fR()
when using them in a
.BR sockaddr_in
structure.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "Section 4.10" ", " "Host and Network Byte Orders",
.IR "\fB<arpa_inet.h>\fP",
.IR "\fB<inttypes.h>\fP",
.IR "\fB<sys_socket.h>\fP"
.P
The System Interfaces volume of POSIX.1\(hy2017,
.IR "\fIconnect\fR\^(\|)",
.IR "\fIgetsockopt\fR\^(\|)",
.IR "\fIhtonl\fR\^(\|)",
.IR "\fIsendmsg\fR\^(\|)",
.IR "\fIsendto\fR\^(\|)",
.IR "\fIsetsockopt\fR\^(\|)"
.\"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1-2017, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, 2018 Edition,
Copyright (C) 2018 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
.PP
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .