generalize sh entry point asm not to assume call dests fit in 12 bits
[musl.git] / include / netinet / in.h
blob1ed3e6faaccb13d8d53852a48c629b3f59fa7777
1 #ifndef _NETINET_IN_H
2 #define _NETINET_IN_H
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
8 #include <features.h>
9 #include <inttypes.h>
10 #include <sys/socket.h>
12 typedef uint16_t in_port_t;
13 typedef uint32_t in_addr_t;
14 struct in_addr { in_addr_t s_addr; };
16 struct sockaddr_in
18 sa_family_t sin_family;
19 in_port_t sin_port;
20 struct in_addr sin_addr;
21 uint8_t sin_zero[8];
24 struct in6_addr
26 union {
27 uint8_t __s6_addr[16];
28 uint16_t __s6_addr16[8];
29 uint32_t __s6_addr32[4];
30 } __in6_union;
32 #define s6_addr __in6_union.__s6_addr
33 #define s6_addr16 __in6_union.__s6_addr16
34 #define s6_addr32 __in6_union.__s6_addr32
36 struct sockaddr_in6
38 sa_family_t sin6_family;
39 in_port_t sin6_port;
40 uint32_t sin6_flowinfo;
41 struct in6_addr sin6_addr;
42 uint32_t sin6_scope_id;
45 struct ipv6_mreq
47 struct in6_addr ipv6mr_multiaddr;
48 unsigned ipv6mr_interface;
51 #define INADDR_ANY ((in_addr_t) 0x00000000)
52 #define INADDR_BROADCAST ((in_addr_t) 0xffffffff)
53 #define INADDR_NONE ((in_addr_t) 0xffffffff)
54 #define INADDR_LOOPBACK ((in_addr_t) 0x7f000001)
56 #define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000)
57 #define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001)
58 #define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002)
59 #define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff)
61 #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
62 #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
64 extern const struct in6_addr in6addr_any, in6addr_loopback;
66 #undef INET_ADDRSTRLEN
67 #undef INET6_ADDRSTRLEN
68 #define INET_ADDRSTRLEN 16
69 #define INET6_ADDRSTRLEN 46
71 uint32_t htonl(uint32_t);
72 uint16_t htons(uint16_t);
73 uint32_t ntohl(uint32_t);
74 uint16_t ntohs(uint16_t);
76 #define IPPROTO_IP 0
77 #define IPPROTO_HOPOPTS 0
78 #define IPPROTO_ICMP 1
79 #define IPPROTO_IGMP 2
80 #define IPPROTO_IPIP 4
81 #define IPPROTO_TCP 6
82 #define IPPROTO_EGP 8
83 #define IPPROTO_PUP 12
84 #define IPPROTO_UDP 17
85 #define IPPROTO_IDP 22
86 #define IPPROTO_TP 29
87 #define IPPROTO_DCCP 33
88 #define IPPROTO_IPV6 41
89 #define IPPROTO_ROUTING 43
90 #define IPPROTO_FRAGMENT 44
91 #define IPPROTO_RSVP 46
92 #define IPPROTO_GRE 47
93 #define IPPROTO_ESP 50
94 #define IPPROTO_AH 51
95 #define IPPROTO_ICMPV6 58
96 #define IPPROTO_NONE 59
97 #define IPPROTO_DSTOPTS 60
98 #define IPPROTO_MTP 92
99 #define IPPROTO_BEETPH 94
100 #define IPPROTO_ENCAP 98
101 #define IPPROTO_PIM 103
102 #define IPPROTO_COMP 108
103 #define IPPROTO_SCTP 132
104 #define IPPROTO_MH 135
105 #define IPPROTO_UDPLITE 136
106 #define IPPROTO_RAW 255
107 #define IPPROTO_MAX 256
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)
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 )
119 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
121 #define IN6_IS_ADDR_LINKLOCAL(a) \
122 ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0x80)
124 #define IN6_IS_ADDR_SITELOCAL(a) \
125 ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0xc0)
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)
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)
136 #define IN6_IS_ADDR_MC_NODELOCAL(a) \
137 (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x1))
139 #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
140 (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x2))
142 #define IN6_IS_ADDR_MC_SITELOCAL(a) \
143 (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x5))
145 #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
146 (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x8))
148 #define IN6_IS_ADDR_MC_GLOBAL(a) \
149 (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0xe))
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))
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)
175 #define IN_LOOPBACKNET 127
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_MULTICAST_IF 32
204 #define IP_MULTICAST_TTL 33
205 #define IP_MULTICAST_LOOP 34
206 #define IP_ADD_MEMBERSHIP 35
207 #define IP_DROP_MEMBERSHIP 36
208 #define IP_UNBLOCK_SOURCE 37
209 #define IP_BLOCK_SOURCE 38
210 #define IP_ADD_SOURCE_MEMBERSHIP 39
211 #define IP_DROP_SOURCE_MEMBERSHIP 40
212 #define IP_MSFILTER 41
213 #define IP_MULTICAST_ALL 49
214 #define IP_UNICAST_IF 50
216 #define IP_RECVRETOPTS IP_RETOPTS
218 #define IP_PMTUDISC_DONT 0
219 #define IP_PMTUDISC_WANT 1
220 #define IP_PMTUDISC_DO 2
221 #define IP_PMTUDISC_PROBE 3
222 #define IP_PMTUDISC_INTERFACE 4
223 #define IP_PMTUDISC_OMIT 5
225 #define IP_DEFAULT_MULTICAST_TTL 1
226 #define IP_DEFAULT_MULTICAST_LOOP 1
227 #define IP_MAX_MEMBERSHIPS 20
229 struct ip_opts
231 struct in_addr ip_dst;
232 char ip_opts[40];
235 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
237 #define MCAST_JOIN_GROUP 42
238 #define MCAST_BLOCK_SOURCE 43
239 #define MCAST_UNBLOCK_SOURCE 44
240 #define MCAST_LEAVE_GROUP 45
241 #define MCAST_JOIN_SOURCE_GROUP 46
242 #define MCAST_LEAVE_SOURCE_GROUP 47
243 #define MCAST_MSFILTER 48
245 #define MCAST_EXCLUDE 0
246 #define MCAST_INCLUDE 1
248 struct ip_mreq
250 struct in_addr imr_multiaddr;
251 struct in_addr imr_interface;
254 struct ip_mreqn
256 struct in_addr imr_multiaddr;
257 struct in_addr imr_address;
258 int imr_ifindex;
261 struct ip_mreq_source {
262 struct in_addr imr_multiaddr;
263 struct in_addr imr_interface;
264 struct in_addr imr_sourceaddr;
267 struct ip_msfilter {
268 struct in_addr imsf_multiaddr;
269 struct in_addr imsf_interface;
270 uint32_t imsf_fmode;
271 uint32_t imsf_numsrc;
272 struct in_addr imsf_slist[1];
274 #define IP_MSFILTER_SIZE(numsrc) \
275 (sizeof(struct ip_msfilter) - sizeof(struct in_addr) \
276 + (numsrc) * sizeof(struct in_addr))
278 struct group_req {
279 uint32_t gr_interface;
280 struct sockaddr_storage gr_group;
283 struct group_source_req {
284 uint32_t gsr_interface;
285 struct sockaddr_storage gsr_group;
286 struct sockaddr_storage gsr_source;
289 struct group_filter {
290 uint32_t gf_interface;
291 struct sockaddr_storage gf_group;
292 uint32_t gf_fmode;
293 uint32_t gf_numsrc;
294 struct sockaddr_storage gf_slist[1];
296 #define GROUP_FILTER_SIZE(numsrc) \
297 (sizeof(struct group_filter) - sizeof(struct sockaddr_storage) \
298 + (numsrc) * sizeof(struct sockaddr_storage))
300 struct in_pktinfo
302 int ipi_ifindex;
303 struct in_addr ipi_spec_dst;
304 struct in_addr ipi_addr;
307 struct in6_pktinfo
309 struct in6_addr ipi6_addr;
310 unsigned ipi6_ifindex;
313 struct ip6_mtuinfo
315 struct sockaddr_in6 ip6m_addr;
316 uint32_t ip6m_mtu;
318 #endif
320 #define IPV6_ADDRFORM 1
321 #define IPV6_2292PKTINFO 2
322 #define IPV6_2292HOPOPTS 3
323 #define IPV6_2292DSTOPTS 4
324 #define IPV6_2292RTHDR 5
325 #define IPV6_2292PKTOPTIONS 6
326 #define IPV6_CHECKSUM 7
327 #define IPV6_2292HOPLIMIT 8
328 #define IPV6_NEXTHOP 9
329 #define IPV6_AUTHHDR 10
330 #define IPV6_UNICAST_HOPS 16
331 #define IPV6_MULTICAST_IF 17
332 #define IPV6_MULTICAST_HOPS 18
333 #define IPV6_MULTICAST_LOOP 19
334 #define IPV6_JOIN_GROUP 20
335 #define IPV6_LEAVE_GROUP 21
336 #define IPV6_ROUTER_ALERT 22
337 #define IPV6_MTU_DISCOVER 23
338 #define IPV6_MTU 24
339 #define IPV6_RECVERR 25
340 #define IPV6_V6ONLY 26
341 #define IPV6_JOIN_ANYCAST 27
342 #define IPV6_LEAVE_ANYCAST 28
343 #define IPV6_IPSEC_POLICY 34
344 #define IPV6_XFRM_POLICY 35
346 #define IPV6_RECVPKTINFO 49
347 #define IPV6_PKTINFO 50
348 #define IPV6_RECVHOPLIMIT 51
349 #define IPV6_HOPLIMIT 52
350 #define IPV6_RECVHOPOPTS 53
351 #define IPV6_HOPOPTS 54
352 #define IPV6_RTHDRDSTOPTS 55
353 #define IPV6_RECVRTHDR 56
354 #define IPV6_RTHDR 57
355 #define IPV6_RECVDSTOPTS 58
356 #define IPV6_DSTOPTS 59
357 #define IPV6_RECVPATHMTU 60
358 #define IPV6_PATHMTU 61
359 #define IPV6_DONTFRAG 62
360 #define IPV6_RECVTCLASS 66
361 #define IPV6_TCLASS 67
362 #define IPV6_AUTOFLOWLABEL 70
363 #define IPV6_ADDR_PREFERENCES 72
364 #define IPV6_MINHOPCOUNT 73
365 #define IPV6_ORIGDSTADDR 74
366 #define IPV6_RECVORIGDSTADDR IPV6_ORIGDSTADDR
367 #define IPV6_TRANSPARENT 75
368 #define IPV6_UNICAST_IF 76
370 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
371 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
372 #define IPV6_RXHOPOPTS IPV6_HOPOPTS
373 #define IPV6_RXDSTOPTS IPV6_DSTOPTS
375 #define IPV6_PMTUDISC_DONT 0
376 #define IPV6_PMTUDISC_WANT 1
377 #define IPV6_PMTUDISC_DO 2
378 #define IPV6_PMTUDISC_PROBE 3
379 #define IPV6_PMTUDISC_INTERFACE 4
380 #define IPV6_PMTUDISC_OMIT 5
382 #define IPV6_PREFER_SRC_TMP 0x0001
383 #define IPV6_PREFER_SRC_PUBLIC 0x0002
384 #define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100
385 #define IPV6_PREFER_SRC_COA 0x0004
386 #define IPV6_PREFER_SRC_HOME 0x0400
387 #define IPV6_PREFER_SRC_CGA 0x0008
388 #define IPV6_PREFER_SRC_NONCGA 0x0800
390 #define IPV6_RTHDR_LOOSE 0
391 #define IPV6_RTHDR_STRICT 1
393 #define IPV6_RTHDR_TYPE_0 0
395 #ifdef __cplusplus
397 #endif
399 #endif