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