1 /* 2 * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this list of 8 * conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef _ADAPT_NETINET_IN_H 32 #define _ADAPT_NETINET_IN_H 33 34 #include <sys/features.h> 35 #include <inttypes.h> 36 #include <sys/socket.h> 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 #define INADDR_ANY ((in_addr_t) 0x00000000) 43 #define INADDR_BROADCAST ((in_addr_t) 0xffffffff) 44 #define INADDR_NONE ((in_addr_t) 0xffffffff) 45 #define INADDR_LOOPBACK ((in_addr_t) 0x7f000001) 46 47 #define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000) 48 #define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001) 49 #define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002) 50 #define INADDR_ALLSNOOPERS_GROUP ((in_addr_t) 0xe000006a) 51 #define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff) 52 53 #undef INET_ADDRSTRLEN 54 #undef INET6_ADDRSTRLEN 55 #define INET_ADDRSTRLEN 16 56 #define INET6_ADDRSTRLEN 46 57 58 #define IPPORT_RESERVED 1024 59 60 #define IPPROTO_IP 0 61 #define IPPROTO_HOPOPTS 0 62 #define IPPROTO_ICMP 1 63 #define IPPROTO_IGMP 2 64 #define IPPROTO_IPIP 4 65 #define IPPROTO_TCP 6 66 #define IPPROTO_EGP 8 67 #define IPPROTO_PUP 12 68 #define IPPROTO_UDP 17 69 #define IPPROTO_IDP 22 70 #define IPPROTO_TP 29 71 #define IPPROTO_DCCP 33 72 #define IPPROTO_IPV6 41 73 #define IPPROTO_ROUTING 43 74 #define IPPROTO_FRAGMENT 44 75 #define IPPROTO_RSVP 46 76 #define IPPROTO_GRE 47 77 #define IPPROTO_ESP 50 78 #define IPPROTO_AH 51 79 #define IPPROTO_ICMPV6 58 80 #define IPPROTO_NONE 59 81 #define IPPROTO_DSTOPTS 60 82 #define IPPROTO_MTP 92 83 #define IPPROTO_BEETPH 94 84 #define IPPROTO_ENCAP 98 85 #define IPPROTO_PIM 103 86 #define IPPROTO_COMP 108 87 #define IPPROTO_SCTP 132 88 #define IPPROTO_MH 135 89 #define IPPROTO_UDPLITE 136 90 #define IPPROTO_MPLS 137 91 #define IPPROTO_RAW 255 92 #define IPPROTO_MAX 256 93 94 #define __ARE_4_EQUAL(a,b) \ 95 (!( (0[a] - 0[b]) | (1[a] - 1[b]) | (2[a] - 2[b]) | (3[a] - 3[b]) )) 96 97 #define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0) 98 #define IN_CLASSA_NET 0xff000000 99 #define IN_CLASSA_NSHIFT 24 100 #define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET) 101 #define IN_CLASSA_MAX 128 102 #define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000) 103 #define IN_CLASSB_NET 0xffff0000 104 #define IN_CLASSB_NSHIFT 16 105 #define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET) 106 #define IN_CLASSB_MAX 65536 107 #define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000) 108 #define IN_CLASSC_NET 0xffffff00 109 #define IN_CLASSC_NSHIFT 8 110 #define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET) 111 #define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000) 112 #define IN_MULTICAST(a) IN_CLASSD(a) 113 #define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000) 114 #define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000) 115 116 #define IN_LOOPBACKNET 127 117 118 #define IP_TOS 1 119 #define IP_TTL 2 120 #define IP_HDRINCL 3 121 #define IP_OPTIONS 4 122 #define IP_ROUTER_ALERT 5 123 #define IP_RECVOPTS 6 124 #define IP_RETOPTS 7 125 #define IP_PKTINFO 8 126 #define IP_PKTOPTIONS 9 127 #define IP_PMTUDISC 10 128 #define IP_MTU_DISCOVER 10 129 #define IP_RECVERR 11 130 #define IP_RECVTTL 12 131 #define IP_RECVTOS 13 132 #define IP_MTU 14 133 #define IP_FREEBIND 15 134 #define IP_IPSEC_POLICY 16 135 #define IP_XFRM_POLICY 17 136 #define IP_PASSSEC 18 137 #define IP_TRANSPARENT 19 138 #define IP_ORIGDSTADDR 20 139 #define IP_RECVORIGDSTADDR IP_ORIGDSTADDR 140 #define IP_MINTTL 21 141 #define IP_NODEFRAG 22 142 #define IP_CHECKSUM 23 143 #define IP_BIND_ADDRESS_NO_PORT 24 144 #define IP_RECVFRAGSIZE 25 145 #define IP_MULTICAST_IF 32 146 #define IP_MULTICAST_TTL 33 147 #define IP_MULTICAST_LOOP 34 148 #define IP_ADD_MEMBERSHIP 35 149 #define IP_DROP_MEMBERSHIP 36 150 #define IP_UNBLOCK_SOURCE 37 151 #define IP_BLOCK_SOURCE 38 152 #define IP_ADD_SOURCE_MEMBERSHIP 39 153 #define IP_DROP_SOURCE_MEMBERSHIP 40 154 #define IP_MSFILTER 41 155 #define IP_MULTICAST_ALL 49 156 #define IP_UNICAST_IF 50 157 158 #define IP_RECVRETOPTS IP_RETOPTS 159 160 #define IP_PMTUDISC_DONT 0 161 #define IP_PMTUDISC_WANT 1 162 #define IP_PMTUDISC_DO 2 163 #define IP_PMTUDISC_PROBE 3 164 #define IP_PMTUDISC_INTERFACE 4 165 #define IP_PMTUDISC_OMIT 5 166 167 #define IP_DEFAULT_MULTICAST_TTL 1 168 #define IP_DEFAULT_MULTICAST_LOOP 1 169 #define IP_MAX_MEMBERSHIPS 20 170 171 typedef uint16_t in_port_t; 172 typedef uint32_t in_addr_t; 173 174 struct in_addr { 175 in_addr_t s_addr; 176 }; 177 178 struct sockaddr_in { 179 sa_family_t sin_family; 180 in_port_t sin_port; 181 struct in_addr sin_addr; 182 uint8_t sin_zero[8]; 183 }; 184 185 struct ip_opts { 186 struct in_addr ip_dst; 187 char ip_opts[40]; 188 }; 189 190 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 191 struct ip_mreq { 192 struct in_addr imr_multiaddr; 193 struct in_addr imr_interface; 194 }; 195 #endif 196 197 #define IPV6_ADDRFORM 1 198 #define IPV6_CHECKSUM 7 199 #define IPV6_NEXTHOP 9 200 #define IPV6_AUTHHDR 10 201 #define IPV6_UNICAST_HOPS 16 202 #define IPV6_MULTICAST_IF 17 203 #define IPV6_MULTICAST_HOPS 18 204 #define IPV6_MULTICAST_LOOP 19 205 #define IPV6_JOIN_GROUP 20 206 #define IPV6_LEAVE_GROUP 21 207 #define IPV6_V6ONLY 26 208 #define IPV6_JOIN_ANYCAST 27 209 #define IPV6_LEAVE_ANYCAST 28 210 #define IPV6_IPSEC_POLICY 34 211 212 #define IN6ADDR_ANY_INIT {{{ 0x00, 0x00, 0x00, 0x00, \ 213 0x00, 0x00, 0x00, 0x00, \ 214 0x00, 0x00, 0x00, 0x00, \ 215 0x00, 0x00, 0x00, 0x00 }}} 216 #define IN6ADDR_LOOPBACK_INIT {{{ 0x00, 0x00, 0x00, 0x00, \ 217 0x00, 0x00, 0x00, 0x00, \ 218 0x00, 0x00, 0x00, 0x00, \ 219 0x00, 0x00, 0x00, 0x01 }}} 220 221 struct in6_addr { 222 union { 223 uint8_t __s6_addr[16]; 224 uint16_t __s6_addr16[8]; 225 uint32_t __s6_addr32[4]; 226 } __in6_union; 227 }; 228 #define s6_addr __in6_union.__s6_addr 229 #define s6_addr16 __in6_union.__s6_addr16 230 #define s6_addr32 __in6_union.__s6_addr32 231 232 struct sockaddr_in6 { 233 sa_family_t sin6_family; 234 in_port_t sin6_port; 235 uint32_t sin6_flowinfo; 236 struct in6_addr sin6_addr; 237 uint32_t sin6_scope_id; 238 }; 239 240 struct ipv6_mreq { 241 struct in6_addr ipv6mr_multiaddr; 242 unsigned ipv6mr_interface; 243 }; 244 245 uint32_t htonl(uint32_t); 246 uint16_t htons(uint16_t); 247 uint32_t ntohl(uint32_t); 248 uint16_t ntohs(uint16_t); 249 250 #ifdef __cplusplus 251 } 252 #endif 253 254 #endif /* !_ADAPT_NETINET_IN_H */ 255