1netinet_in.h(0P)           POSIX Programmer's Manual          netinet_in.h(0P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       netinet/in.h — Internet address family
13

SYNOPSIS

15       #include <netinet/in.h>
16

DESCRIPTION

18       The <netinet/in.h> header shall define the following types:
19
20       in_port_t Equivalent to the type uint16_t as described in <inttypes.h>.
21
22       in_addr_t Equivalent to the type uint32_t as described in <inttypes.h>.
23
24       The  <netinet_in.h>  header  shall  define  the  sa_family_t  type   as
25       described in <sys/socket.h>.
26
27       The  <netinet_in.h>  header shall define the uint8_t and uint32_t types
28       as described in <inttypes.h>.  Inclusion of the  <netinet/in.h>  header
29       may also make visible all symbols from <inttypes.h> and <sys/socket.h>.
30
31       The  <netinet/in.h>  header  shall  define the in_addr structure, which
32       shall include at least the following member:
33
34
35           in_addr_t  s_addr
36
37       The <netinet/in.h> header shall define the sockaddr_in structure, which
38       shall include at least the following members:
39
40
41           sa_family_t     sin_family   AF_INET.
42           in_port_t       sin_port     Port number.
43           struct in_addr  sin_addr     IP address.
44
45       The sin_port and sin_addr members shall be in network byte order.
46
47       The  sockaddr_in  structure is used to store addresses for the Internet
48       address family.  Pointers to this type shall be cast by applications to
49       struct sockaddr * for use with socket functions.
50
51       The  <netinet/in.h>  header  shall define the in6_addr structure, which
52       shall include at least the following member:
53
54
55           uint8_t s6_addr[16]
56
57       This array is used to contain a 128-bit IPv6 address, stored in network
58       byte order.
59
60       The  <netinet/in.h>  header  shall  define  the sockaddr_in6 structure,
61       which shall include at least the following members:
62
63
64           sa_family_t      sin6_family    AF_INET6.
65           in_port_t        sin6_port      Port number.
66           uint32_t         sin6_flowinfo  IPv6 traffic class and flow information.
67           struct in6_addr  sin6_addr      IPv6 address.
68           uint32_t         sin6_scope_id  Set of interfaces for a scope.
69
70       The sin6_port and sin6_addr members shall be in network byte order.
71
72       Prior to calling a function in this standard which reads values from  a
73       sockaddr_in6 structure (for example, bind() or connect()), the applica‐
74       tion shall ensure that all members  of  the  structure,  including  any
75       additional non-standard members, if any, are initialized.  If the sock‐
76       addr_in6 structure has a non-standard member, and  that  member  has  a
77       value  other  than the value that would result from default initializa‐
78       tion, the behavior of any function in this standard that  reads  values
79       from  the  sockaddr_in6  structure is implementation-defined. All func‐
80       tions in this standard that return data  in  a  sockaddr_in6  structure
81       (for example, getaddrinfo() or accept()) shall initialize the structure
82       in a way that meets the above requirements, and shall ensure that  each
83       non-standard  member, if any, has a value that produces the same behav‐
84       ior as default initialization would in all functions in  this  standard
85       which read values from a sockaddr_in6 structure.
86
87       The  sin6_scope_id  field  is a 32-bit integer that identifies a set of
88       interfaces as appropriate for the scope of the address carried  in  the
89       sin6_addr  field.  For  a  link  scope sin6_addr, the application shall
90       ensure that sin6_scope_id is a link index. For a site scope  sin6_addr,
91       the  application  shall  ensure that sin6_scope_id is a site index. The
92       mapping of sin6_scope_id to an interface or set of interfaces is imple‐
93       mentation-defined.
94
95       The  <netinet/in.h>  header  shall declare the following external vari‐
96       able:
97
98
99           const struct in6_addr in6addr_any
100
101       This variable is initialized by the system to contain the wildcard IPv6
102       address.  The  <netinet/in.h>  header also defines the IN6ADDR_ANY_INIT
103       macro. This macro must be constant at compile time and can be  used  to
104       initialize  a  variable  of  type  struct in6_addr to the IPv6 wildcard
105       address.
106
107       The <netinet/in.h> header shall declare the  following  external  vari‐
108       able:
109
110
111           const struct in6_addr in6addr_loopback
112
113       This variable is initialized by the system to contain the loopback IPv6
114       address. The  <netinet/in.h>  header  also  defines  the  IN6ADDR_LOOP‐
115       BACK_INIT macro. This macro must be constant at compile time and can be
116       used to initialize a variable of type struct in6_addr to the IPv6 loop‐
117       back address.
118
119       The  <netinet/in.h>  header shall define the ipv6_mreq structure, which
120       shall include at least the following members:
121
122
123           struct in6_addr  ipv6mr_multiaddr  IPv6 multicast address.
124           unsigned         ipv6mr_interface  Interface index.
125
126       The <netinet/in.h> header shall define the following symbolic constants
127       for  use  as  values of the level argument of getsockopt() and setsock‐
128       opt():
129
130       IPPROTO_IP      Internet protocol.
131
132       IPPROTO_IPV6    Internet Protocol Version 6.
133
134       IPPROTO_ICMP    Control message protocol.
135
136       IPPROTO_RAW     Raw IP Packets Protocol.
137
138       IPPROTO_TCP     Transmission control protocol.
139
140       IPPROTO_UDP     User datagram protocol.
141
142       The <netinet/in.h> header shall define the following symbolic  constant
143       for use as a local address in the structure passed to bind():
144
145       INADDR_ANY      IPv4 wildcard address.
146
147       The  <netinet/in.h> header shall define the following symbolic constant
148       for use as a destination address in the structures passed to connect(),
149       sendmsg(), and sendto():
150
151       INADDR_BROADCAST
152                       IPv4 broadcast address.
153
154       The <netinet/in.h> header shall define the following symbolic constant,
155       with the value specified, to help applications declare buffers  of  the
156       proper size to store IPv4 addresses in string form:
157
158       INET_ADDRSTRLEN 16. Length of the string form for IP.
159
160       The htonl(), htons(), ntohl(), and ntohs() functions shall be available
161       as described in <arpa/inet.h>.  Inclusion of the <netinet/in.h>  header
162       may also make visible all symbols from <arpa/inet.h>.
163
164       The <netinet/in.h> header shall define the following symbolic constant,
165       with the value specified, to help applications declare buffers  of  the
166       proper size to store IPv6 addresses in string form:
167
168       INET6_ADDRSTRLEN
169                       46. Length of the string form for IPv6.
170
171       The  <netinet/in.h>  header  shall  define  the following symbolic con‐
172       stants, with distinct integer values, for use in the option_name  argu‐
173       ment  in  the  getsockopt() or setsockopt() functions at protocol level
174       IPPROTO_IPV6:
175
176       IPV6_JOIN_GROUP Join a multicast group.
177
178       IPV6_LEAVE_GROUP
179                       Quit a multicast group.
180
181       IPV6_MULTICAST_HOPS
182                       Multicast hop limit.
183
184       IPV6_MULTICAST_IF
185                       Interface to use for outgoing multicast packets.
186
187       IPV6_MULTICAST_LOOP
188                       Multicast packets  are  delivered  back  to  the  local
189                       application.
190
191       IPV6_UNICAST_HOPS
192                       Unicast hop limit.
193
194       IPV6_V6ONLY     Restrict AF_INET6 socket to IPv6 communications only.
195
196       The  <netinet/in.h>  header shall define the following macros that test
197       for special IPv6 addresses. Each macro is of type int and takes a  sin‐
198       gle argument of type const struct in6_addr *:
199
200       IN6_IS_ADDR_UNSPECIFIED
201             Unspecified address.
202
203       IN6_IS_ADDR_LOOPBACK
204             Loopback address.
205
206       IN6_IS_ADDR_MULTICAST
207             Multicast address.
208
209       IN6_IS_ADDR_LINKLOCAL
210             Unicast link-local address.
211
212       IN6_IS_ADDR_SITELOCAL
213             Unicast site-local address.
214
215       IN6_IS_ADDR_V4MAPPED
216             IPv4 mapped address.
217
218       IN6_IS_ADDR_V4COMPAT
219             IPv4-compatible address.
220
221       IN6_IS_ADDR_MC_NODELOCAL
222             Multicast node-local address.
223
224       IN6_IS_ADDR_MC_LINKLOCAL
225             Multicast link-local address.
226
227       IN6_IS_ADDR_MC_SITELOCAL
228             Multicast site-local address.
229
230       IN6_IS_ADDR_MC_ORGLOCAL
231             Multicast organization-local address.
232
233       IN6_IS_ADDR_MC_GLOBAL
234             Multicast global address.
235
236       The following sections are informative.
237

APPLICATION USAGE

239       Although applications are required to initialize all members (including
240       any non-standard ones) of a sockaddr_in6 structure,  the  same  is  not
241       required  for the sockaddr_in structure, since historically many appli‐
242       cations only initialized the standard members. Despite  this,  applica‐
243       tions  are  encouraged to initialize sockaddr_in structures in a manner
244       similar to the required initialization of sockaddr_in6 structures.
245
246       Although it is common practice to initialize a  sockaddr_in6  structure
247       using:
248
249
250           struct sockaddr_in6 sa;
251           memset(&sa, 0, sizeof sa);
252
253       this  method  is  not  portable according to this standard, because the
254       structure can contain pointer or floating-point members  that  are  not
255       required to have an all-bits-zero representation after default initial‐
256       ization. Portable methods make use of default initialization; for exam‐
257       ple:
258
259
260           struct sockaddr_in6 sa = { 0 };
261
262       or:
263
264
265           static struct sockaddr_in6 sa_init;
266           struct sockaddr_in6 sa = sa_init;
267
268       A  future  version  of  this standard may require that a pointer object
269       with an all-bits-zero representation is a null pointer, and that  sock‐
270       addr_in6  does  not have any floating-point members if a floating-point
271       object with an all-bits-zero representation does  not  have  the  value
272       0.0.
273

RATIONALE

275       The  INADDR_ANY  and INADDR_BROADCAST values are byte-order-neutral and
276       thus their byte order is not specified. Many implementations have addi‐
277       tional  constants  as extensions, such as INADDR_LOOPBACK, that are not
278       byte-order-neutral. Traditionally, these constants  are  in  host  byte
279       order,  requiring  the  use of htonl() when using them in a sockaddr_in
280       structure.
281

FUTURE DIRECTIONS

283       None.
284

SEE ALSO

286       Section 4.10,  Host  and  Network  Byte  Orders,  <arpa_inet.h>,  <int‐
287       types.h>, <sys_socket.h>
288
289       The  System Interfaces volume of POSIX.1‐2017, connect(), getsockopt(),
290       htonl(), sendmsg(), sendto(), setsockopt()
291
293       Portions of this text are reprinted and reproduced in  electronic  form
294       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
295       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
296       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
297       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
298       event of any discrepancy between this version and the original IEEE and
299       The Open Group Standard, the original IEEE and The Open Group  Standard
300       is  the  referee document. The original Standard can be obtained online
301       at http://www.opengroup.org/unix/online.html .
302
303       Any typographical or formatting errors that appear  in  this  page  are
304       most likely to have been introduced during the conversion of the source
305       files to man page format. To report such errors,  see  https://www.ker
306       nel.org/doc/man-pages/reporting_bugs.html .
307
308
309
310IEEE/The Open Group                  2017                     netinet_in.h(0P)
Impressum