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