1
0

in.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. #ifndef _NETINET_IN_H
  2. #define _NETINET_IN_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <features.h>
  7. #include <inttypes.h>
  8. #include <sys/socket.h>
  9. typedef uint16_t in_port_t;
  10. typedef uint32_t in_addr_t;
  11. struct in_addr { in_addr_t s_addr; };
  12. struct sockaddr_in {
  13. sa_family_t sin_family;
  14. in_port_t sin_port;
  15. struct in_addr sin_addr;
  16. uint8_t sin_zero[8];
  17. };
  18. struct in6_addr {
  19. union {
  20. uint8_t __s6_addr[16];
  21. uint16_t __s6_addr16[8];
  22. uint32_t __s6_addr32[4];
  23. } __in6_union;
  24. };
  25. #define s6_addr __in6_union.__s6_addr
  26. #define s6_addr16 __in6_union.__s6_addr16
  27. #define s6_addr32 __in6_union.__s6_addr32
  28. struct sockaddr_in6 {
  29. sa_family_t sin6_family;
  30. in_port_t sin6_port;
  31. uint32_t sin6_flowinfo;
  32. struct in6_addr sin6_addr;
  33. uint32_t sin6_scope_id;
  34. };
  35. struct ipv6_mreq {
  36. struct in6_addr ipv6mr_multiaddr;
  37. unsigned ipv6mr_interface;
  38. };
  39. #define INADDR_ANY ((in_addr_t) 0x00000000)
  40. #define INADDR_BROADCAST ((in_addr_t) 0xffffffff)
  41. #define INADDR_NONE ((in_addr_t) 0xffffffff)
  42. #define INADDR_LOOPBACK ((in_addr_t) 0x7f000001)
  43. #define INADDR_DUMMY ((in_addr_t) 0xc0000008)
  44. #define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000)
  45. #define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001)
  46. #define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002)
  47. #define INADDR_ALLSNOOPERS_GROUP ((in_addr_t) 0xe000006a)
  48. #define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff)
  49. #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
  50. #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
  51. extern const struct in6_addr in6addr_any, in6addr_loopback;
  52. #define INET_ADDRSTRLEN 16
  53. #define INET6_ADDRSTRLEN 46
  54. uint32_t htonl(uint32_t);
  55. uint16_t htons(uint16_t);
  56. uint32_t ntohl(uint32_t);
  57. uint16_t ntohs(uint16_t);
  58. #define IPPORT_RESERVED 1024
  59. #define IPPROTO_IP 0
  60. #define IPPROTO_HOPOPTS 0
  61. #define IPPROTO_ICMP 1
  62. #define IPPROTO_IGMP 2
  63. #define IPPROTO_IPIP 4
  64. #define IPPROTO_TCP 6
  65. #define IPPROTO_EGP 8
  66. #define IPPROTO_PUP 12
  67. #define IPPROTO_UDP 17
  68. #define IPPROTO_IDP 22
  69. #define IPPROTO_TP 29
  70. #define IPPROTO_DCCP 33
  71. #define IPPROTO_IPV6 41
  72. #define IPPROTO_ROUTING 43
  73. #define IPPROTO_FRAGMENT 44
  74. #define IPPROTO_RSVP 46
  75. #define IPPROTO_GRE 47
  76. #define IPPROTO_ESP 50
  77. #define IPPROTO_AH 51
  78. #define IPPROTO_ICMPV6 58
  79. #define IPPROTO_NONE 59
  80. #define IPPROTO_DSTOPTS 60
  81. #define IPPROTO_MTP 92
  82. #define IPPROTO_BEETPH 94
  83. #define IPPROTO_ENCAP 98
  84. #define IPPROTO_PIM 103
  85. #define IPPROTO_COMP 108
  86. #define IPPROTO_SCTP 132
  87. #define IPPROTO_MH 135
  88. #define IPPROTO_UDPLITE 136
  89. #define IPPROTO_MPLS 137
  90. #define IPPROTO_ETHERNET 143
  91. #define IPPROTO_RAW 255
  92. #define IPPROTO_MPTCP 262
  93. #define IPPROTO_MAX 263
  94. #define IN6_IS_ADDR_UNSPECIFIED(a) \
  95. (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \
  96. ((uint32_t *) (a))[2] == 0 && ((uint32_t *) (a))[3] == 0)
  97. #define IN6_IS_ADDR_LOOPBACK(a) \
  98. (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \
  99. ((uint32_t *) (a))[2] == 0 && \
  100. ((uint8_t *) (a))[12] == 0 && ((uint8_t *) (a))[13] == 0 && \
  101. ((uint8_t *) (a))[14] == 0 && ((uint8_t *) (a))[15] == 1 )
  102. #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
  103. #define IN6_IS_ADDR_LINKLOCAL(a) \
  104. ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0x80)
  105. #define IN6_IS_ADDR_SITELOCAL(a) \
  106. ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0xc0)
  107. #define IN6_IS_ADDR_V4MAPPED(a) \
  108. (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \
  109. ((uint8_t *) (a))[8] == 0 && ((uint8_t *) (a))[9] == 0 && \
  110. ((uint8_t *) (a))[10] == 0xff && ((uint8_t *) (a))[11] == 0xff)
  111. #define IN6_IS_ADDR_V4COMPAT(a) \
  112. (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \
  113. ((uint32_t *) (a))[2] == 0 && ((uint8_t *) (a))[15] > 1)
  114. #define IN6_IS_ADDR_MC_NODELOCAL(a) \
  115. (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x1))
  116. #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
  117. (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x2))
  118. #define IN6_IS_ADDR_MC_SITELOCAL(a) \
  119. (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x5))
  120. #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
  121. (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x8))
  122. #define IN6_IS_ADDR_MC_GLOBAL(a) \
  123. (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0xe))
  124. #define __ARE_4_EQUAL(a,b) \
  125. (!( (0[a]-0[b]) | (1[a]-1[b]) | (2[a]-2[b]) | (3[a]-3[b]) ))
  126. #define IN6_ARE_ADDR_EQUAL(a,b) \
  127. __ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b))
  128. #define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0)
  129. #define IN_CLASSA_NET 0xff000000
  130. #define IN_CLASSA_NSHIFT 24
  131. #define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET)
  132. #define IN_CLASSA_MAX 128
  133. #define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
  134. #define IN_CLASSB_NET 0xffff0000
  135. #define IN_CLASSB_NSHIFT 16
  136. #define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET)
  137. #define IN_CLASSB_MAX 65536
  138. #define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
  139. #define IN_CLASSC_NET 0xffffff00
  140. #define IN_CLASSC_NSHIFT 8
  141. #define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET)
  142. #define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
  143. #define IN_MULTICAST(a) IN_CLASSD(a)
  144. #define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
  145. #define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)
  146. #define IN_LOOPBACKNET 127
  147. #define IP_TOS 1
  148. #define IP_TTL 2
  149. #define IP_HDRINCL 3
  150. #define IP_OPTIONS 4
  151. #define IP_ROUTER_ALERT 5
  152. #define IP_RECVOPTS 6
  153. #define IP_RETOPTS 7
  154. #define IP_PKTINFO 8
  155. #define IP_PKTOPTIONS 9
  156. #define IP_PMTUDISC 10
  157. #define IP_MTU_DISCOVER 10
  158. #define IP_RECVERR 11
  159. #define IP_RECVTTL 12
  160. #define IP_RECVTOS 13
  161. #define IP_MTU 14
  162. #define IP_FREEBIND 15
  163. #define IP_IPSEC_POLICY 16
  164. #define IP_XFRM_POLICY 17
  165. #define IP_PASSSEC 18
  166. #define IP_TRANSPARENT 19
  167. #define IP_ORIGDSTADDR 20
  168. #define IP_RECVORIGDSTADDR IP_ORIGDSTADDR
  169. #define IP_MINTTL 21
  170. #define IP_NODEFRAG 22
  171. #define IP_CHECKSUM 23
  172. #define IP_BIND_ADDRESS_NO_PORT 24
  173. #define IP_RECVFRAGSIZE 25
  174. #define IP_RECVERR_RFC4884 26
  175. #define IP_MULTICAST_IF 32
  176. #define IP_MULTICAST_TTL 33
  177. #define IP_MULTICAST_LOOP 34
  178. #define IP_ADD_MEMBERSHIP 35
  179. #define IP_DROP_MEMBERSHIP 36
  180. #define IP_UNBLOCK_SOURCE 37
  181. #define IP_BLOCK_SOURCE 38
  182. #define IP_ADD_SOURCE_MEMBERSHIP 39
  183. #define IP_DROP_SOURCE_MEMBERSHIP 40
  184. #define IP_MSFILTER 41
  185. #define IP_MULTICAST_ALL 49
  186. #define IP_UNICAST_IF 50
  187. #define IP_RECVRETOPTS IP_RETOPTS
  188. #define IP_PMTUDISC_DONT 0
  189. #define IP_PMTUDISC_WANT 1
  190. #define IP_PMTUDISC_DO 2
  191. #define IP_PMTUDISC_PROBE 3
  192. #define IP_PMTUDISC_INTERFACE 4
  193. #define IP_PMTUDISC_OMIT 5
  194. #define IP_DEFAULT_MULTICAST_TTL 1
  195. #define IP_DEFAULT_MULTICAST_LOOP 1
  196. #define IP_MAX_MEMBERSHIPS 20
  197. struct ip_opts {
  198. struct in_addr ip_dst;
  199. char ip_opts[40];
  200. };
  201. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  202. #define MCAST_JOIN_GROUP 42
  203. #define MCAST_BLOCK_SOURCE 43
  204. #define MCAST_UNBLOCK_SOURCE 44
  205. #define MCAST_LEAVE_GROUP 45
  206. #define MCAST_JOIN_SOURCE_GROUP 46
  207. #define MCAST_LEAVE_SOURCE_GROUP 47
  208. #define MCAST_MSFILTER 48
  209. #define MCAST_EXCLUDE 0
  210. #define MCAST_INCLUDE 1
  211. struct ip_mreq {
  212. struct in_addr imr_multiaddr;
  213. struct in_addr imr_interface;
  214. };
  215. struct ip_mreqn {
  216. struct in_addr imr_multiaddr;
  217. struct in_addr imr_address;
  218. int imr_ifindex;
  219. };
  220. struct ip_mreq_source {
  221. struct in_addr imr_multiaddr;
  222. struct in_addr imr_interface;
  223. struct in_addr imr_sourceaddr;
  224. };
  225. struct ip_msfilter {
  226. struct in_addr imsf_multiaddr;
  227. struct in_addr imsf_interface;
  228. uint32_t imsf_fmode;
  229. uint32_t imsf_numsrc;
  230. struct in_addr imsf_slist[1];
  231. };
  232. #define IP_MSFILTER_SIZE(numsrc) \
  233. (sizeof(struct ip_msfilter) - sizeof(struct in_addr) \
  234. + (numsrc) * sizeof(struct in_addr))
  235. struct group_req {
  236. uint32_t gr_interface;
  237. struct sockaddr_storage gr_group;
  238. };
  239. struct group_source_req {
  240. uint32_t gsr_interface;
  241. struct sockaddr_storage gsr_group;
  242. struct sockaddr_storage gsr_source;
  243. };
  244. struct group_filter {
  245. uint32_t gf_interface;
  246. struct sockaddr_storage gf_group;
  247. uint32_t gf_fmode;
  248. uint32_t gf_numsrc;
  249. struct sockaddr_storage gf_slist[1];
  250. };
  251. #define GROUP_FILTER_SIZE(numsrc) \
  252. (sizeof(struct group_filter) - sizeof(struct sockaddr_storage) \
  253. + (numsrc) * sizeof(struct sockaddr_storage))
  254. struct in_pktinfo {
  255. int ipi_ifindex;
  256. struct in_addr ipi_spec_dst;
  257. struct in_addr ipi_addr;
  258. };
  259. struct in6_pktinfo {
  260. struct in6_addr ipi6_addr;
  261. unsigned ipi6_ifindex;
  262. };
  263. struct ip6_mtuinfo {
  264. struct sockaddr_in6 ip6m_addr;
  265. uint32_t ip6m_mtu;
  266. };
  267. #endif
  268. #define IPV6_ADDRFORM 1
  269. #define IPV6_2292PKTINFO 2
  270. #define IPV6_2292HOPOPTS 3
  271. #define IPV6_2292DSTOPTS 4
  272. #define IPV6_2292RTHDR 5
  273. #define IPV6_2292PKTOPTIONS 6
  274. #define IPV6_CHECKSUM 7
  275. #define IPV6_2292HOPLIMIT 8
  276. #define IPV6_NEXTHOP 9
  277. #define IPV6_AUTHHDR 10
  278. #define IPV6_UNICAST_HOPS 16
  279. #define IPV6_MULTICAST_IF 17
  280. #define IPV6_MULTICAST_HOPS 18
  281. #define IPV6_MULTICAST_LOOP 19
  282. #define IPV6_JOIN_GROUP 20
  283. #define IPV6_LEAVE_GROUP 21
  284. #define IPV6_ROUTER_ALERT 22
  285. #define IPV6_MTU_DISCOVER 23
  286. #define IPV6_MTU 24
  287. #define IPV6_RECVERR 25
  288. #define IPV6_V6ONLY 26
  289. #define IPV6_JOIN_ANYCAST 27
  290. #define IPV6_LEAVE_ANYCAST 28
  291. #define IPV6_MULTICAST_ALL 29
  292. #define IPV6_ROUTER_ALERT_ISOLATE 30
  293. #define IPV6_IPSEC_POLICY 34
  294. #define IPV6_XFRM_POLICY 35
  295. #define IPV6_HDRINCL 36
  296. #define IPV6_RECVPKTINFO 49
  297. #define IPV6_PKTINFO 50
  298. #define IPV6_RECVHOPLIMIT 51
  299. #define IPV6_HOPLIMIT 52
  300. #define IPV6_RECVHOPOPTS 53
  301. #define IPV6_HOPOPTS 54
  302. #define IPV6_RTHDRDSTOPTS 55
  303. #define IPV6_RECVRTHDR 56
  304. #define IPV6_RTHDR 57
  305. #define IPV6_RECVDSTOPTS 58
  306. #define IPV6_DSTOPTS 59
  307. #define IPV6_RECVPATHMTU 60
  308. #define IPV6_PATHMTU 61
  309. #define IPV6_DONTFRAG 62
  310. #define IPV6_RECVTCLASS 66
  311. #define IPV6_TCLASS 67
  312. #define IPV6_AUTOFLOWLABEL 70
  313. #define IPV6_ADDR_PREFERENCES 72
  314. #define IPV6_MINHOPCOUNT 73
  315. #define IPV6_ORIGDSTADDR 74
  316. #define IPV6_RECVORIGDSTADDR IPV6_ORIGDSTADDR
  317. #define IPV6_TRANSPARENT 75
  318. #define IPV6_UNICAST_IF 76
  319. #define IPV6_RECVFRAGSIZE 77
  320. #define IPV6_FREEBIND 78
  321. #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
  322. #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
  323. #define IPV6_RXHOPOPTS IPV6_HOPOPTS
  324. #define IPV6_RXDSTOPTS IPV6_DSTOPTS
  325. #define IPV6_PMTUDISC_DONT 0
  326. #define IPV6_PMTUDISC_WANT 1
  327. #define IPV6_PMTUDISC_DO 2
  328. #define IPV6_PMTUDISC_PROBE 3
  329. #define IPV6_PMTUDISC_INTERFACE 4
  330. #define IPV6_PMTUDISC_OMIT 5
  331. #define IPV6_PREFER_SRC_TMP 0x0001
  332. #define IPV6_PREFER_SRC_PUBLIC 0x0002
  333. #define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100
  334. #define IPV6_PREFER_SRC_COA 0x0004
  335. #define IPV6_PREFER_SRC_HOME 0x0400
  336. #define IPV6_PREFER_SRC_CGA 0x0008
  337. #define IPV6_PREFER_SRC_NONCGA 0x0800
  338. #define IPV6_RTHDR_LOOSE 0
  339. #define IPV6_RTHDR_STRICT 1
  340. #define IPV6_RTHDR_TYPE_0 0
  341. #define __UAPI_DEF_IN_ADDR 0
  342. #define __UAPI_DEF_IN_IPPROTO 0
  343. #define __UAPI_DEF_IN_PKTINFO 0
  344. #define __UAPI_DEF_IP_MREQ 0
  345. #define __UAPI_DEF_SOCKADDR_IN 0
  346. #define __UAPI_DEF_IN_CLASS 0
  347. #define __UAPI_DEF_IN6_ADDR 0
  348. #define __UAPI_DEF_IN6_ADDR_ALT 0
  349. #define __UAPI_DEF_SOCKADDR_IN6 0
  350. #define __UAPI_DEF_IPV6_MREQ 0
  351. #define __UAPI_DEF_IPPROTO_V6 0
  352. #define __UAPI_DEF_IPV6_OPTIONS 0
  353. #define __UAPI_DEF_IN6_PKTINFO 0
  354. #define __UAPI_DEF_IP6_MTUINFO 0
  355. #ifdef __cplusplus
  356. }
  357. #endif
  358. #endif