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