]> git.ipfire.org Git - thirdparty/glibc.git/blame - inet/netinet/in.h
socket: Use may_alias on sockaddr structs (bug 19622)
[thirdparty/glibc.git] / inet / netinet / in.h
CommitLineData
dff8da6b 1/* Copyright (C) 1991-2024 Free Software Foundation, Inc.
54d79e99
UD
2 This file is part of the GNU C Library.
3
478b92f0 4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
54d79e99
UD
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
478b92f0 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 12 Lesser General Public License for more details.
54d79e99 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6 15 License along with the GNU C Library; if not, see
5a82c748 16 <https://www.gnu.org/licenses/>. */
28f540f4
RM
17
18#ifndef _NETINET_IN_H
28f540f4 19#define _NETINET_IN_H 1
5107cf1d 20
28f540f4 21#include <features.h>
17680430 22#include <bits/stdint-uintn.h>
a4596570 23#include <sys/socket.h>
3584d5fb 24#include <bits/types.h>
f8b87ef0 25
28f540f4 26
1fb05e3d
UD
27__BEGIN_DECLS
28
6c82a2f8
CD
29/* Internet address. */
30typedef uint32_t in_addr_t;
31struct in_addr
32 {
33 in_addr_t s_addr;
34 };
35
36/* Get system-specific definitions. */
37#include <bits/in.h>
38
df4ef2ab
UD
39/* Standard well-defined IP protocols. */
40enum
41 {
3996f34b 42 IPPROTO_IP = 0, /* Dummy protocol for TCP. */
126f53e8 43#define IPPROTO_IP IPPROTO_IP
3996f34b 44 IPPROTO_ICMP = 1, /* Internet Control Message Protocol. */
126f53e8 45#define IPPROTO_ICMP IPPROTO_ICMP
3996f34b 46 IPPROTO_IGMP = 2, /* Internet Group Management Protocol. */
126f53e8 47#define IPPROTO_IGMP IPPROTO_IGMP
3996f34b 48 IPPROTO_IPIP = 4, /* IPIP tunnels (older KA9Q tunnels use 94). */
126f53e8 49#define IPPROTO_IPIP IPPROTO_IPIP
3996f34b 50 IPPROTO_TCP = 6, /* Transmission Control Protocol. */
126f53e8 51#define IPPROTO_TCP IPPROTO_TCP
3996f34b 52 IPPROTO_EGP = 8, /* Exterior Gateway Protocol. */
126f53e8 53#define IPPROTO_EGP IPPROTO_EGP
3996f34b 54 IPPROTO_PUP = 12, /* PUP protocol. */
126f53e8 55#define IPPROTO_PUP IPPROTO_PUP
3996f34b 56 IPPROTO_UDP = 17, /* User Datagram Protocol. */
126f53e8 57#define IPPROTO_UDP IPPROTO_UDP
3996f34b 58 IPPROTO_IDP = 22, /* XNS IDP protocol. */
126f53e8 59#define IPPROTO_IDP IPPROTO_IDP
085320f5 60 IPPROTO_TP = 29, /* SO Transport Protocol Class 4. */
126f53e8 61#define IPPROTO_TP IPPROTO_TP
372bfcac
UD
62 IPPROTO_DCCP = 33, /* Datagram Congestion Control Protocol. */
63#define IPPROTO_DCCP IPPROTO_DCCP
3996f34b 64 IPPROTO_IPV6 = 41, /* IPv6 header. */
126f53e8 65#define IPPROTO_IPV6 IPPROTO_IPV6
085320f5 66 IPPROTO_RSVP = 46, /* Reservation Protocol. */
126f53e8 67#define IPPROTO_RSVP IPPROTO_RSVP
085320f5 68 IPPROTO_GRE = 47, /* General Routing Encapsulation. */
126f53e8 69#define IPPROTO_GRE IPPROTO_GRE
3996f34b 70 IPPROTO_ESP = 50, /* encapsulating security payload. */
126f53e8 71#define IPPROTO_ESP IPPROTO_ESP
3996f34b 72 IPPROTO_AH = 51, /* authentication header. */
126f53e8 73#define IPPROTO_AH IPPROTO_AH
085320f5 74 IPPROTO_MTP = 92, /* Multicast Transport Protocol. */
126f53e8 75#define IPPROTO_MTP IPPROTO_MTP
6c82a2f8
CD
76 IPPROTO_BEETPH = 94, /* IP option pseudo header for BEET. */
77#define IPPROTO_BEETPH IPPROTO_BEETPH
085320f5 78 IPPROTO_ENCAP = 98, /* Encapsulation Header. */
126f53e8 79#define IPPROTO_ENCAP IPPROTO_ENCAP
085320f5 80 IPPROTO_PIM = 103, /* Protocol Independent Multicast. */
126f53e8 81#define IPPROTO_PIM IPPROTO_PIM
d01d6319 82 IPPROTO_COMP = 108, /* Compression Header Protocol. */
126f53e8 83#define IPPROTO_COMP IPPROTO_COMP
b5e3d66b
JM
84 IPPROTO_L2TP = 115, /* Layer 2 Tunnelling Protocol. */
85#define IPPROTO_L2TP IPPROTO_L2TP
5e826ab5
UD
86 IPPROTO_SCTP = 132, /* Stream Control Transmission Protocol. */
87#define IPPROTO_SCTP IPPROTO_SCTP
372bfcac
UD
88 IPPROTO_UDPLITE = 136, /* UDP-Lite protocol. */
89#define IPPROTO_UDPLITE IPPROTO_UDPLITE
04d9a38b
JM
90 IPPROTO_MPLS = 137, /* MPLS in IP. */
91#define IPPROTO_MPLS IPPROTO_MPLS
f9ac84f9
JM
92 IPPROTO_ETHERNET = 143, /* Ethernet-within-IPv6 Encapsulation. */
93#define IPPROTO_ETHERNET IPPROTO_ETHERNET
3996f34b 94 IPPROTO_RAW = 255, /* Raw IP packets. */
126f53e8 95#define IPPROTO_RAW IPPROTO_RAW
f9ac84f9
JM
96 IPPROTO_MPTCP = 262, /* Multipath TCP connection. */
97#define IPPROTO_MPTCP IPPROTO_MPTCP
df4ef2ab
UD
98 IPPROTO_MAX
99 };
100
1c1e7fb6 101/* If __USE_KERNEL_IPV6_DEFS is 1 then the user has included the kernel
6c82a2f8 102 network headers first and we should use those ABI-identical definitions
1c1e7fb6
CD
103 instead of our own, otherwise 0. */
104#if !__USE_KERNEL_IPV6_DEFS
6c82a2f8
CD
105enum
106 {
107 IPPROTO_HOPOPTS = 0, /* IPv6 Hop-by-Hop options. */
108#define IPPROTO_HOPOPTS IPPROTO_HOPOPTS
109 IPPROTO_ROUTING = 43, /* IPv6 routing header. */
110#define IPPROTO_ROUTING IPPROTO_ROUTING
111 IPPROTO_FRAGMENT = 44, /* IPv6 fragmentation header. */
112#define IPPROTO_FRAGMENT IPPROTO_FRAGMENT
113 IPPROTO_ICMPV6 = 58, /* ICMPv6. */
114#define IPPROTO_ICMPV6 IPPROTO_ICMPV6
115 IPPROTO_NONE = 59, /* IPv6 no next header. */
116#define IPPROTO_NONE IPPROTO_NONE
117 IPPROTO_DSTOPTS = 60, /* IPv6 destination options. */
118#define IPPROTO_DSTOPTS IPPROTO_DSTOPTS
3bfff2ed 119 IPPROTO_MH = 135 /* IPv6 mobility header. */
6c82a2f8
CD
120#define IPPROTO_MH IPPROTO_MH
121 };
122#endif /* !__USE_KERNEL_IPV6_DEFS */
ad483238
UD
123
124/* Type to represent a port. */
125typedef uint16_t in_port_t;
126
df4ef2ab 127/* Standard well-known ports. */
28f540f4
RM
128enum
129 {
130 IPPORT_ECHO = 7, /* Echo service. */
131 IPPORT_DISCARD = 9, /* Discard transmissions service. */
132 IPPORT_SYSTAT = 11, /* System status service. */
133 IPPORT_DAYTIME = 13, /* Time of day service. */
134 IPPORT_NETSTAT = 15, /* Network status service. */
135 IPPORT_FTP = 21, /* File Transfer Protocol. */
136 IPPORT_TELNET = 23, /* Telnet protocol. */
137 IPPORT_SMTP = 25, /* Simple Mail Transfer Protocol. */
138 IPPORT_TIMESERVER = 37, /* Timeserver service. */
139 IPPORT_NAMESERVER = 42, /* Domain Name Service. */
293e360a 140 IPPORT_WHOIS = 43, /* Internet Whois service. */
28f540f4
RM
141 IPPORT_MTP = 57,
142
143 IPPORT_TFTP = 69, /* Trivial File Transfer Protocol. */
144 IPPORT_RJE = 77,
145 IPPORT_FINGER = 79, /* Finger service. */
146 IPPORT_TTYLINK = 87,
147 IPPORT_SUPDUP = 95, /* SUPDUP protocol. */
148
149
150 IPPORT_EXECSERVER = 512, /* execd service. */
151 IPPORT_LOGINSERVER = 513, /* rlogind service. */
152 IPPORT_CMDSERVER = 514,
153 IPPORT_EFSSERVER = 520,
154
155 /* UDP ports. */
156 IPPORT_BIFFUDP = 512,
157 IPPORT_WHOSERVER = 513,
158 IPPORT_ROUTESERVER = 520,
159
160 /* Ports less than this value are reserved for privileged processes. */
161 IPPORT_RESERVED = 1024,
162
163 /* Ports greater this value are reserved for (non-privileged) servers. */
59dd8641 164 IPPORT_USERRESERVED = 5000
28f540f4
RM
165 };
166
df4ef2ab
UD
167/* Definitions of the bits in an Internet address integer.
168
169 On subnets, host and network parts are found according to
170 the subnet mask, not these masks. */
171
ad483238 172#define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0)
df4ef2ab
UD
173#define IN_CLASSA_NET 0xff000000
174#define IN_CLASSA_NSHIFT 24
175#define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET)
176#define IN_CLASSA_MAX 128
177
ad483238 178#define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
df4ef2ab
UD
179#define IN_CLASSB_NET 0xffff0000
180#define IN_CLASSB_NSHIFT 16
181#define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET)
182#define IN_CLASSB_MAX 65536
183
ad483238 184#define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
df4ef2ab
UD
185#define IN_CLASSC_NET 0xffffff00
186#define IN_CLASSC_NSHIFT 8
187#define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET)
188
ad483238 189#define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
df4ef2ab
UD
190#define IN_MULTICAST(a) IN_CLASSD(a)
191
ad483238
UD
192#define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
193#define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)
df4ef2ab
UD
194
195/* Address to accept any incoming messages. */
ad483238 196#define INADDR_ANY ((in_addr_t) 0x00000000)
df4ef2ab 197/* Address to send to all hosts. */
ad483238 198#define INADDR_BROADCAST ((in_addr_t) 0xffffffff)
df4ef2ab 199/* Address indicating an error return. */
ad483238 200#define INADDR_NONE ((in_addr_t) 0xffffffff)
fb894896
JM
201/* Dummy address for source of ICMPv6 errors converted to IPv4 (RFC
202 7600). */
203#define INADDR_DUMMY ((in_addr_t) 0xc0000008)
df4ef2ab
UD
204
205/* Network number for local host loopback. */
b0081e6c 206#define IN_LOOPBACKNET 127
df4ef2ab
UD
207/* Address to loopback in software to local host. */
208#ifndef INADDR_LOOPBACK
ad483238 209# define INADDR_LOOPBACK ((in_addr_t) 0x7f000001) /* Inet 127.0.0.1. */
df4ef2ab
UD
210#endif
211
ff152e3f 212/* Defines for Multicast INADDR. */
ad483238
UD
213#define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000) /* 224.0.0.0 */
214#define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001) /* 224.0.0.1 */
215#define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002) /* 224.0.0.2 */
dc91a19e 216#define INADDR_ALLSNOOPERS_GROUP ((in_addr_t) 0xe000006a) /* 224.0.0.106 */
ad483238 217#define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff) /* 224.0.0.255 */
ff152e3f 218
1c1e7fb6 219#if !__USE_KERNEL_IPV6_DEFS
1fb05e3d
UD
220/* IPv6 address */
221struct in6_addr
222 {
223 union
224 {
a53d3f82 225 uint8_t __u6_addr8[16];
a53d3f82
UD
226 uint16_t __u6_addr16[8];
227 uint32_t __u6_addr32[4];
a53d3f82
UD
228 } __in6_u;
229#define s6_addr __in6_u.__u6_addr8
acd7f096 230#ifdef __USE_MISC
a53d3f82
UD
231# define s6_addr16 __in6_u.__u6_addr16
232# define s6_addr32 __in6_u.__u6_addr32
233#endif
1fb05e3d 234 };
6c82a2f8 235#endif /* !__USE_KERNEL_IPV6_DEFS */
1fb05e3d
UD
236
237extern const struct in6_addr in6addr_any; /* :: */
238extern const struct in6_addr in6addr_loopback; /* ::1 */
f79973fa
UD
239#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
240#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
1fb05e3d
UD
241
242#define INET_ADDRSTRLEN 16
243#define INET6_ADDRSTRLEN 46
244
df4ef2ab
UD
245
246/* Structure describing an Internet socket address. */
8d7b6b4c 247struct __attribute_struct_may_alias__ sockaddr_in
df4ef2ab
UD
248 {
249 __SOCKADDR_COMMON (sin_);
ad483238 250 in_port_t sin_port; /* Port number. */
df4ef2ab
UD
251 struct in_addr sin_addr; /* Internet address. */
252
253 /* Pad to size of `struct sockaddr'. */
a04549c1
JM
254 unsigned char sin_zero[sizeof (struct sockaddr)
255 - __SOCKADDR_COMMON_SIZE
256 - sizeof (in_port_t)
257 - sizeof (struct in_addr)];
df4ef2ab
UD
258 };
259
8d7b6b4c
FW
260#if __USE_KERNEL_IPV6_DEFS
261struct __attribute_struct_may_alias__ sockaddr_in6;
262#else
1fb05e3d 263/* Ditto, for IPv6. */
8d7b6b4c 264struct __attribute_struct_may_alias__ sockaddr_in6
1fb05e3d
UD
265 {
266 __SOCKADDR_COMMON (sin6_);
ad483238 267 in_port_t sin6_port; /* Transport layer port # */
3996f34b 268 uint32_t sin6_flowinfo; /* IPv6 flow information */
1522c368 269 struct in6_addr sin6_addr; /* IPv6 address */
c0bc5f7b 270 uint32_t sin6_scope_id; /* IPv6 scope-id */
1fb05e3d 271 };
6c82a2f8 272#endif /* !__USE_KERNEL_IPV6_DEFS */
70682735 273
acd7f096 274#ifdef __USE_MISC
70682735
UD
275/* IPv4 multicast request. */
276struct ip_mreq
277 {
278 /* IP multicast address of group. */
279 struct in_addr imr_multiaddr;
280
281 /* Local IP address of interface. */
282 struct in_addr imr_interface;
283 };
284
a2ee8c65
ST
285/* IPv4 multicast request with interface index. */
286struct ip_mreqn
287 {
288 /* IP multicast address of group. */
289 struct in_addr imr_multiaddr;
290
291 /* Local IP address of interface. */
292 struct in_addr imr_address;
293
294 /* Interface index. */
295 int imr_ifindex;
296 };
297
70682735
UD
298struct ip_mreq_source
299 {
300 /* IP multicast address of group. */
301 struct in_addr imr_multiaddr;
302
e35ac97c 303 /* IP address of interface. */
70682735
UD
304 struct in_addr imr_interface;
305
e35ac97c 306 /* IP address of source. */
70682735
UD
307 struct in_addr imr_sourceaddr;
308 };
a53d3f82
UD
309#endif
310
1c1e7fb6 311#if !__USE_KERNEL_IPV6_DEFS
70682735 312/* Likewise, for IPv6. */
1fb05e3d
UD
313struct ipv6_mreq
314 {
315 /* IPv6 multicast address of group */
316 struct in6_addr ipv6mr_multiaddr;
317
3996f34b 318 /* local interface */
724049ba 319 unsigned int ipv6mr_interface;
1fb05e3d 320 };
6c82a2f8 321#endif /* !__USE_KERNEL_IPV6_DEFS */
70682735 322
acd7f096 323#ifdef __USE_MISC
b82276d1
UD
324/* Multicast group request. */
325struct group_req
326 {
327 /* Interface index. */
328 uint32_t gr_interface;
329
330 /* Group address. */
331 struct sockaddr_storage gr_group;
332 };
333
334struct group_source_req
335 {
336 /* Interface index. */
337 uint32_t gsr_interface;
338
339 /* Group address. */
340 struct sockaddr_storage gsr_group;
341
342 /* Source address. */
343 struct sockaddr_storage gsr_source;
344 };
345
346
489aa29d
UD
347/* Full-state filter operations. */
348struct ip_msfilter
349 {
350 /* IP multicast address of group. */
351 struct in_addr imsf_multiaddr;
352
353 /* Local IP address of interface. */
354 struct in_addr imsf_interface;
355
356 /* Filter mode. */
357 uint32_t imsf_fmode;
358
359 /* Number of source addresses. */
360 uint32_t imsf_numsrc;
361 /* Source addresses. */
362 struct in_addr imsf_slist[1];
363 };
364
365#define IP_MSFILTER_SIZE(numsrc) (sizeof (struct ip_msfilter) \
366 - sizeof (struct in_addr) \
367 + (numsrc) * sizeof (struct in_addr))
368
369struct group_filter
370 {
371 /* Interface index. */
372 uint32_t gf_interface;
373
374 /* Group address. */
375 struct sockaddr_storage gf_group;
376
377 /* Filter mode. */
378 uint32_t gf_fmode;
379
380 /* Number of source addresses. */
381 uint32_t gf_numsrc;
382 /* Source addresses. */
383 struct sockaddr_storage gf_slist[1];
384};
385
386#define GROUP_FILTER_SIZE(numsrc) (sizeof (struct group_filter) \
387 - sizeof (struct sockaddr_storage) \
388 + ((numsrc) \
389 * sizeof (struct sockaddr_storage)))
a53d3f82 390#endif
489aa29d 391
ceb2d9aa 392/* Functions to convert between host and network byte order.
28f540f4 393
ceb2d9aa
UD
394 Please note that these functions normally take `unsigned long int' or
395 `unsigned short int' values as arguments and also return them. But
396 this was a short-sighted decision since on different systems the types
397 may have different representations but the values are always the same. */
398
c1422e5b
UD
399extern uint32_t ntohl (uint32_t __netlong) __THROW __attribute__ ((__const__));
400extern uint16_t ntohs (uint16_t __netshort)
401 __THROW __attribute__ ((__const__));
402extern uint32_t htonl (uint32_t __hostlong)
403 __THROW __attribute__ ((__const__));
404extern uint16_t htons (uint16_t __hostshort)
405 __THROW __attribute__ ((__const__));
a3e59be8 406
28f540f4
RM
407#include <endian.h>
408
1522c368
UD
409/* Get machine dependent optimized versions of byte swapping functions. */
410#include <bits/byteswap.h>
6a1cefac 411#include <bits/uintn-identity.h>
1522c368 412
ad483238
UD
413#ifdef __OPTIMIZE__
414/* We can optimize calls to the conversion functions. Either nothing has
415 to be done or we are using directly the byte-swapping functions which
416 often can be inlined. */
417# if __BYTE_ORDER == __BIG_ENDIAN
28f540f4
RM
418/* The host byte order is the same as network byte order,
419 so these functions are all just identity. */
6a1cefac
JM
420# define ntohl(x) __uint32_identity (x)
421# define ntohs(x) __uint16_identity (x)
422# define htonl(x) __uint32_identity (x)
423# define htons(x) __uint16_identity (x)
ad483238
UD
424# else
425# if __BYTE_ORDER == __LITTLE_ENDIAN
426# define ntohl(x) __bswap_32 (x)
427# define ntohs(x) __bswap_16 (x)
428# define htonl(x) __bswap_32 (x)
429# define htons(x) __bswap_16 (x)
430# endif
60c96635 431# endif
28f540f4
RM
432#endif
433
aff2453d
UD
434#ifdef __GNUC__
435# define IN6_IS_ADDR_UNSPECIFIED(a) \
436 (__extension__ \
a784e502 437 ({ const struct in6_addr *__a = (const struct in6_addr *) (a); \
0abbe7cd
FW
438 __a->__in6_u.__u6_addr32[0] == 0 \
439 && __a->__in6_u.__u6_addr32[1] == 0 \
440 && __a->__in6_u.__u6_addr32[2] == 0 \
441 && __a->__in6_u.__u6_addr32[3] == 0; }))
aff2453d
UD
442
443# define IN6_IS_ADDR_LOOPBACK(a) \
444 (__extension__ \
a784e502 445 ({ const struct in6_addr *__a = (const struct in6_addr *) (a); \
0abbe7cd
FW
446 __a->__in6_u.__u6_addr32[0] == 0 \
447 && __a->__in6_u.__u6_addr32[1] == 0 \
448 && __a->__in6_u.__u6_addr32[2] == 0 \
449 && __a->__in6_u.__u6_addr32[3] == htonl (1); }))
aff2453d
UD
450
451# define IN6_IS_ADDR_LINKLOCAL(a) \
452 (__extension__ \
a784e502 453 ({ const struct in6_addr *__a = (const struct in6_addr *) (a); \
0abbe7cd 454 (__a->__in6_u.__u6_addr32[0] & htonl (0xffc00000)) == htonl (0xfe800000); }))
aff2453d
UD
455
456# define IN6_IS_ADDR_SITELOCAL(a) \
457 (__extension__ \
a784e502 458 ({ const struct in6_addr *__a = (const struct in6_addr *) (a); \
0abbe7cd 459 (__a->__in6_u.__u6_addr32[0] & htonl (0xffc00000)) == htonl (0xfec00000); }))
aff2453d
UD
460
461# define IN6_IS_ADDR_V4MAPPED(a) \
462 (__extension__ \
a784e502 463 ({ const struct in6_addr *__a = (const struct in6_addr *) (a); \
0abbe7cd
FW
464 __a->__in6_u.__u6_addr32[0] == 0 \
465 && __a->__in6_u.__u6_addr32[1] == 0 \
466 && __a->__in6_u.__u6_addr32[2] == htonl (0xffff); }))
aff2453d
UD
467
468# define IN6_IS_ADDR_V4COMPAT(a) \
469 (__extension__ \
a784e502 470 ({ const struct in6_addr *__a = (const struct in6_addr *) (a); \
0abbe7cd
FW
471 __a->__in6_u.__u6_addr32[0] == 0 \
472 && __a->__in6_u.__u6_addr32[1] == 0 \
473 && __a->__in6_u.__u6_addr32[2] == 0 \
474 && ntohl (__a->__in6_u.__u6_addr32[3]) > 1; }))
aff2453d
UD
475
476# define IN6_ARE_ADDR_EQUAL(a,b) \
477 (__extension__ \
a784e502
UD
478 ({ const struct in6_addr *__a = (const struct in6_addr *) (a); \
479 const struct in6_addr *__b = (const struct in6_addr *) (b); \
0abbe7cd
FW
480 __a->__in6_u.__u6_addr32[0] == __b->__in6_u.__u6_addr32[0] \
481 && __a->__in6_u.__u6_addr32[1] == __b->__in6_u.__u6_addr32[1] \
482 && __a->__in6_u.__u6_addr32[2] == __b->__in6_u.__u6_addr32[2] \
483 && __a->__in6_u.__u6_addr32[3] == __b->__in6_u.__u6_addr32[3]; }))
aff2453d
UD
484#else
485# define IN6_IS_ADDR_UNSPECIFIED(a) \
a784e502
UD
486 (((const uint32_t *) (a))[0] == 0 \
487 && ((const uint32_t *) (a))[1] == 0 \
488 && ((const uint32_t *) (a))[2] == 0 \
489 && ((const uint32_t *) (a))[3] == 0)
1fb05e3d 490
aff2453d 491# define IN6_IS_ADDR_LOOPBACK(a) \
a784e502
UD
492 (((const uint32_t *) (a))[0] == 0 \
493 && ((const uint32_t *) (a))[1] == 0 \
494 && ((const uint32_t *) (a))[2] == 0 \
495 && ((const uint32_t *) (a))[3] == htonl (1))
1fb05e3d 496
aff2453d 497# define IN6_IS_ADDR_LINKLOCAL(a) \
a784e502 498 ((((const uint32_t *) (a))[0] & htonl (0xffc00000)) \
c3301189 499 == htonl (0xfe800000))
1fb05e3d 500
aff2453d 501# define IN6_IS_ADDR_SITELOCAL(a) \
a784e502 502 ((((const uint32_t *) (a))[0] & htonl (0xffc00000)) \
c3301189 503 == htonl (0xfec00000))
1fb05e3d 504
aff2453d 505# define IN6_IS_ADDR_V4MAPPED(a) \
a784e502
UD
506 ((((const uint32_t *) (a))[0] == 0) \
507 && (((const uint32_t *) (a))[1] == 0) \
508 && (((const uint32_t *) (a))[2] == htonl (0xffff)))
1fb05e3d 509
aff2453d 510# define IN6_IS_ADDR_V4COMPAT(a) \
a784e502
UD
511 ((((const uint32_t *) (a))[0] == 0) \
512 && (((const uint32_t *) (a))[1] == 0) \
513 && (((const uint32_t *) (a))[2] == 0) \
514 && (ntohl (((const uint32_t *) (a))[3]) > 1))
3996f34b 515
aff2453d 516# define IN6_ARE_ADDR_EQUAL(a,b) \
a784e502
UD
517 ((((const uint32_t *) (a))[0] == ((const uint32_t *) (b))[0]) \
518 && (((const uint32_t *) (a))[1] == ((const uint32_t *) (b))[1]) \
519 && (((const uint32_t *) (a))[2] == ((const uint32_t *) (b))[2]) \
520 && (((const uint32_t *) (a))[3] == ((const uint32_t *) (b))[3]))
aff2453d
UD
521#endif
522
a784e502 523#define IN6_IS_ADDR_MULTICAST(a) (((const uint8_t *) (a))[0] == 0xff)
8f2ece69 524
acd7f096 525#ifdef __USE_MISC
bfbc5754 526/* Bind socket to a privileged IP port. */
c1422e5b 527extern int bindresvport (int __sockfd, struct sockaddr_in *__sock_in) __THROW;
1fb05e3d 528
c1301d9a
UD
529/* The IPv6 version of this function. */
530extern int bindresvport6 (int __sockfd, struct sockaddr_in6 *__sock_in)
531 __THROW;
a53d3f82 532#endif
1f205a47 533
8619129f
UD
534
535#define IN6_IS_ADDR_MC_NODELOCAL(a) \
c3301189 536 (IN6_IS_ADDR_MULTICAST(a) \
a784e502 537 && ((((const uint8_t *) (a))[1] & 0xf) == 0x1))
8619129f
UD
538
539#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
c3301189 540 (IN6_IS_ADDR_MULTICAST(a) \
a784e502 541 && ((((const uint8_t *) (a))[1] & 0xf) == 0x2))
8619129f
UD
542
543#define IN6_IS_ADDR_MC_SITELOCAL(a) \
c3301189 544 (IN6_IS_ADDR_MULTICAST(a) \
a784e502 545 && ((((const uint8_t *) (a))[1] & 0xf) == 0x5))
8619129f
UD
546
547#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
c3301189 548 (IN6_IS_ADDR_MULTICAST(a) \
a784e502 549 && ((((const uint8_t *) (a))[1] & 0xf) == 0x8))
8619129f
UD
550
551#define IN6_IS_ADDR_MC_GLOBAL(a) \
c3301189 552 (IN6_IS_ADDR_MULTICAST(a) \
a784e502 553 && ((((const uint8_t *) (a))[1] & 0xf) == 0xe))
8619129f 554
a53d3f82
UD
555
556#ifdef __USE_GNU
bea9b193
RM
557struct cmsghdr; /* Forward declaration. */
558
1c1e7fb6 559#if !__USE_KERNEL_IPV6_DEFS
1f205a47 560/* IPv6 packet information. */
0501d603 561struct in6_pktinfo
1f205a47 562 {
07bfff20
UD
563 struct in6_addr ipi6_addr; /* src/dst IPv6 address */
564 unsigned int ipi6_ifindex; /* send/recv interface index */
565 };
566
567/* IPv6 MTU information. */
568struct ip6_mtuinfo
569 {
570 struct sockaddr_in6 ip6m_addr; /* dst address including zone ID */
571 uint32_t ip6m_mtu; /* path MTU in host byte order */
1f205a47 572 };
cb43bb0d 573#endif /* !__USE_KERNEL_IPV6_DEFS */
a4596570 574
07bfff20
UD
575/* Obsolete hop-by-hop and Destination Options Processing (RFC 2292). */
576extern int inet6_option_space (int __nbytes)
577 __THROW __attribute_deprecated__;
a4596570 578extern int inet6_option_init (void *__bp, struct cmsghdr **__cmsgp,
07bfff20 579 int __type) __THROW __attribute_deprecated__;
a4596570 580extern int inet6_option_append (struct cmsghdr *__cmsg,
a784e502 581 const uint8_t *__typep, int __multx,
07bfff20 582 int __plusy) __THROW __attribute_deprecated__;
a4596570 583extern uint8_t *inet6_option_alloc (struct cmsghdr *__cmsg, int __datalen,
07bfff20
UD
584 int __multx, int __plusy)
585 __THROW __attribute_deprecated__;
a784e502 586extern int inet6_option_next (const struct cmsghdr *__cmsg,
07bfff20
UD
587 uint8_t **__tptrp)
588 __THROW __attribute_deprecated__;
a784e502 589extern int inet6_option_find (const struct cmsghdr *__cmsg,
07bfff20
UD
590 uint8_t **__tptrp, int __type)
591 __THROW __attribute_deprecated__;
592
593
594/* Hop-by-Hop and Destination Options Processing (RFC 3542). */
595extern int inet6_opt_init (void *__extbuf, socklen_t __extlen) __THROW;
596extern int inet6_opt_append (void *__extbuf, socklen_t __extlen, int __offset,
597 uint8_t __type, socklen_t __len, uint8_t __align,
598 void **__databufp) __THROW;
599extern int inet6_opt_finish (void *__extbuf, socklen_t __extlen, int __offset)
600 __THROW;
601extern int inet6_opt_set_val (void *__databuf, int __offset, void *__val,
602 socklen_t __vallen) __THROW;
603extern int inet6_opt_next (void *__extbuf, socklen_t __extlen, int __offset,
604 uint8_t *__typep, socklen_t *__lenp,
605 void **__databufp) __THROW;
606extern int inet6_opt_find (void *__extbuf, socklen_t __extlen, int __offset,
607 uint8_t __type, socklen_t *__lenp,
608 void **__databufp) __THROW;
609extern int inet6_opt_get_val (void *__databuf, int __offset, void *__val,
610 socklen_t __vallen) __THROW;
611
612
613/* Routing Header Option (RFC 3542). */
614extern socklen_t inet6_rth_space (int __type, int __segments) __THROW;
615extern void *inet6_rth_init (void *__bp, socklen_t __bp_len, int __type,
616 int __segments) __THROW;
a784e502
UD
617extern int inet6_rth_add (void *__bp, const struct in6_addr *__addr) __THROW;
618extern int inet6_rth_reverse (const void *__in, void *__out) __THROW;
619extern int inet6_rth_segments (const void *__bp) __THROW;
620extern struct in6_addr *inet6_rth_getaddr (const void *__bp, int __index)
07bfff20 621 __THROW;
f89d6892
UD
622
623
624/* Multicast source filter support. */
625
626/* Get IPv4 source filter. */
a3437831 627extern int getipv4sourcefilter (int __s, struct in_addr __interface_addr,
f89d6892
UD
628 struct in_addr __group, uint32_t *__fmode,
629 uint32_t *__numsrc, struct in_addr *__slist)
630 __THROW;
631
632/* Set IPv4 source filter. */
a3437831 633extern int setipv4sourcefilter (int __s, struct in_addr __interface_addr,
f89d6892 634 struct in_addr __group, uint32_t __fmode,
d3c99ad1 635 uint32_t __numsrc,
a784e502 636 const struct in_addr *__slist)
f89d6892
UD
637 __THROW;
638
639
640/* Get source filter. */
a3437831 641extern int getsourcefilter (int __s, uint32_t __interface_addr,
a784e502 642 const struct sockaddr *__group,
d3c99ad1
UD
643 socklen_t __grouplen, uint32_t *__fmode,
644 uint32_t *__numsrc,
f89d6892
UD
645 struct sockaddr_storage *__slist) __THROW;
646
647/* Set source filter. */
a3437831 648extern int setsourcefilter (int __s, uint32_t __interface_addr,
a784e502 649 const struct sockaddr *__group,
d3c99ad1
UD
650 socklen_t __grouplen, uint32_t __fmode,
651 uint32_t __numsrc,
a784e502 652 const struct sockaddr_storage *__slist) __THROW;
a4596570
UD
653#endif /* use GNU */
654
1fb05e3d
UD
655__END_DECLS
656
28f540f4 657#endif /* netinet/in.h */