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