Debian Codegraph @

libc-top-half/musl/include/netinet/in.h

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