in.h 22 KB

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