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