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