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