blob: 89188c78b40a6fc3fbd1c14187e92938227a1565 [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001#ifndef _NETINET_IN_H
2#define _NETINET_IN_H
3
Rich Felker3ed8c9f2011-11-10 20:40:06 -05004#ifdef __cplusplus
5extern "C" {
6#endif
7
Szabolcs Nagy119645b2013-01-11 01:54:53 +01008#include <features.h>
Rich Felker9448b052013-07-22 11:22:36 -04009#include <inttypes.h>
10#include <sys/socket.h>
Szabolcs Nagy119645b2013-01-11 01:54:53 +010011
Rich Felker9448b052013-07-22 11:22:36 -040012typedef uint16_t in_port_t;
13typedef uint32_t in_addr_t;
14struct in_addr { in_addr_t s_addr; };
Rich Felker0b44a032011-02-12 00:22:29 -050015
16struct sockaddr_in
17{
18 sa_family_t sin_family;
19 in_port_t sin_port;
20 struct in_addr sin_addr;
21 uint8_t sin_zero[8];
22};
23
24struct in6_addr
25{
26 union {
27 uint8_t __s6_addr[16];
Rich Felkerca2d3c62012-05-03 22:12:46 -040028 uint16_t __s6_addr16[8];
Rich Felker0b44a032011-02-12 00:22:29 -050029 uint32_t __s6_addr32[4];
30 } __in6_union;
31};
32#define s6_addr __in6_union.__s6_addr
Rich Felkerca2d3c62012-05-03 22:12:46 -040033#define s6_addr16 __in6_union.__s6_addr16
Rich Felker0b44a032011-02-12 00:22:29 -050034#define s6_addr32 __in6_union.__s6_addr32
35
36struct sockaddr_in6
37{
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;
43};
44
45struct ipv6_mreq
46{
47 struct in6_addr ipv6mr_multiaddr;
48 unsigned ipv6mr_interface;
49};
50
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)
55
Rich Felkerc91ad4f2013-12-20 11:42:03 -050056#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)
60
Rich Felker0b44a032011-02-12 00:22:29 -050061#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 } } }
63
64extern const struct in6_addr in6addr_any, in6addr_loopback;
65
66#undef INET_ADDRSTRLEN
67#undef INET6_ADDRSTRLEN
68#define INET_ADDRSTRLEN 16
69#define INET6_ADDRSTRLEN 46
70
71uint32_t htonl(uint32_t);
72uint16_t htons(uint16_t);
73uint32_t ntohl(uint32_t);
74uint16_t ntohs(uint16_t);
75
76#define IPPROTO_IP 0
Rich Felkerb10d0232012-09-08 19:52:51 -040077#define IPPROTO_HOPOPTS 0
Rich Felker0b44a032011-02-12 00:22:29 -050078#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
Rich Felker5d893e52013-01-01 20:19:20 -050087#define IPPROTO_DCCP 33
Rich Felker0b44a032011-02-12 00:22:29 -050088#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
Szabolcs Nagy0dc630e2013-09-15 02:41:36 +000099#define IPPROTO_BEETPH 94
Rich Felker0b44a032011-02-12 00:22:29 -0500100#define IPPROTO_ENCAP 98
101#define IPPROTO_PIM 103
102#define IPPROTO_COMP 108
Rich Felker5d893e52013-01-01 20:19:20 -0500103#define IPPROTO_SCTP 132
Szabolcs Nagy0dc630e2013-09-15 02:41:36 +0000104#define IPPROTO_MH 135
Rich Felker5d893e52013-01-01 20:19:20 -0500105#define IPPROTO_UDPLITE 136
Rich Felker0b44a032011-02-12 00:22:29 -0500106#define IPPROTO_RAW 255
Rich Felkerf59cedb2012-09-08 19:43:34 -0400107#define IPPROTO_MAX 256
Rich Felker0b44a032011-02-12 00:22:29 -0500108
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)
112
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 )
118
119#define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
120
121#define IN6_IS_ADDR_LINKLOCAL(a) \
122 ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0x80)
123
124#define IN6_IS_ADDR_SITELOCAL(a) \
125 ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0xc0)
126
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)
131
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)
135
136#define IN6_IS_ADDR_MC_NODELOCAL(a) \
137 (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x1))
138
139#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
140 (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x2))
141
142#define IN6_IS_ADDR_MC_SITELOCAL(a) \
143 (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x5))
144
145#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
146 (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x8))
147
148#define IN6_IS_ADDR_MC_GLOBAL(a) \
149 (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0xe))
150
Rich Felkerb47fdcd2012-05-11 11:05:41 -0400151#define __ARE_4_EQUAL(a,b) \
Szabolcs Nagye74f3b02014-02-11 18:02:06 +0100152 (!( (0[a]-0[b]) | (1[a]-1[b]) | (2[a]-2[b]) | (3[a]-3[b]) ))
Rich Felkerb47fdcd2012-05-11 11:05:41 -0400153#define IN6_ARE_ADDR_EQUAL(a,b) \
154 __ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b))
155
Rich Felker0b44a032011-02-12 00:22:29 -0500156#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)
Rich Felker0b44a032011-02-12 00:22:29 -0500174
Rich Felker2b55a612011-04-06 15:44:39 -0400175#define IN_LOOPBACKNET 127
176
Rich Felkerc8175662011-09-18 15:31:44 -0400177
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
Szabolcs Nagyc3504682014-05-30 14:15:48 +0200201#define IP_NODEFRAG 22
Rich Felkerc8175662011-09-18 15:31:44 -0400202#define IP_MULTICAST_IF 32
203#define IP_MULTICAST_TTL 33
204#define IP_MULTICAST_LOOP 34
205#define IP_ADD_MEMBERSHIP 35
206#define IP_DROP_MEMBERSHIP 36
207#define IP_UNBLOCK_SOURCE 37
208#define IP_BLOCK_SOURCE 38
209#define IP_ADD_SOURCE_MEMBERSHIP 39
210#define IP_DROP_SOURCE_MEMBERSHIP 40
211#define IP_MSFILTER 41
Szabolcs Nagy119645b2013-01-11 01:54:53 +0100212#define IP_MULTICAST_ALL 49
213#define IP_UNICAST_IF 50
214
Rich Felkerc8175662011-09-18 15:31:44 -0400215#define IP_RECVRETOPTS IP_RETOPTS
216
217#define IP_PMTUDISC_DONT 0
218#define IP_PMTUDISC_WANT 1
219#define IP_PMTUDISC_DO 2
220#define IP_PMTUDISC_PROBE 3
Szabolcs Nagyd82db852014-02-25 00:28:31 +0100221#define IP_PMTUDISC_INTERFACE 4
Szabolcs Nagyc3504682014-05-30 14:15:48 +0200222#define IP_PMTUDISC_OMIT 5
Rich Felkerc8175662011-09-18 15:31:44 -0400223
Rich Felkerc8175662011-09-18 15:31:44 -0400224#define IP_DEFAULT_MULTICAST_TTL 1
225#define IP_DEFAULT_MULTICAST_LOOP 1
226#define IP_MAX_MEMBERSHIPS 20
227
228struct ip_opts
229{
230 struct in_addr ip_dst;
231 char ip_opts[40];
232};
233
Rich Felkeracde0132014-01-08 18:54:33 -0500234#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
235
236#define MCAST_JOIN_GROUP 42
237#define MCAST_BLOCK_SOURCE 43
238#define MCAST_UNBLOCK_SOURCE 44
239#define MCAST_LEAVE_GROUP 45
240#define MCAST_JOIN_SOURCE_GROUP 46
241#define MCAST_LEAVE_SOURCE_GROUP 47
242#define MCAST_MSFILTER 48
243
244#define MCAST_EXCLUDE 0
245#define MCAST_INCLUDE 1
246
Rich Felkerc8175662011-09-18 15:31:44 -0400247struct ip_mreq
248{
249 struct in_addr imr_multiaddr;
250 struct in_addr imr_interface;
251};
252
253struct ip_mreqn
254{
255 struct in_addr imr_multiaddr;
256 struct in_addr imr_address;
257 int imr_ifindex;
258};
259
Timo Teräs7c0ca4d2013-07-31 12:05:14 +0300260struct ip_mreq_source {
261 struct in_addr imr_multiaddr;
262 struct in_addr imr_interface;
263 struct in_addr imr_sourceaddr;
264};
265
266struct ip_msfilter {
267 struct in_addr imsf_multiaddr;
268 struct in_addr imsf_interface;
269 uint32_t imsf_fmode;
270 uint32_t imsf_numsrc;
271 struct in_addr imsf_slist[1];
272};
273#define IP_MSFILTER_SIZE(numsrc) \
274 (sizeof(struct ip_msfilter) - sizeof(struct in_addr) \
275 + (numsrc) * sizeof(struct in_addr))
276
Timo Teräs7c0ca4d2013-07-31 12:05:14 +0300277struct group_req {
278 uint32_t gr_interface;
279 struct sockaddr_storage gr_group;
280};
281
282struct group_source_req {
283 uint32_t gsr_interface;
284 struct sockaddr_storage gsr_group;
285 struct sockaddr_storage gsr_source;
286};
287
288struct group_filter {
289 uint32_t gf_interface;
290 struct sockaddr_storage gf_group;
291 uint32_t gf_fmode;
292 uint32_t gf_numsrc;
293 struct sockaddr_storage gf_slist[1];
294};
295#define GROUP_FILTER_SIZE(numsrc) \
296 (sizeof(struct group_filter) - sizeof(struct sockaddr_storage) \
297 + (numsrc) * sizeof(struct sockaddr_storage))
Timo Teräs7c0ca4d2013-07-31 12:05:14 +0300298
Rich Felkerc8175662011-09-18 15:31:44 -0400299struct in_pktinfo
300{
301 int ipi_ifindex;
302 struct in_addr ipi_spec_dst;
303 struct in_addr ipi_addr;
304};
305
306struct in6_pktinfo
307{
308 struct in6_addr ipi6_addr;
309 unsigned ipi6_ifindex;
310};
311
Rich Felkerfd9e01e2011-09-20 20:02:48 -0400312struct ip6_mtuinfo
Rich Felkerc8175662011-09-18 15:31:44 -0400313{
314 struct sockaddr_in6 ip6m_addr;
315 uint32_t ip6m_mtu;
316};
Rich Felkeracde0132014-01-08 18:54:33 -0500317#endif
Rich Felkerc8175662011-09-18 15:31:44 -0400318
319#define IPV6_ADDRFORM 1
320#define IPV6_2292PKTINFO 2
321#define IPV6_2292HOPOPTS 3
322#define IPV6_2292DSTOPTS 4
323#define IPV6_2292RTHDR 5
324#define IPV6_2292PKTOPTIONS 6
325#define IPV6_CHECKSUM 7
326#define IPV6_2292HOPLIMIT 8
Rich Felkerc8175662011-09-18 15:31:44 -0400327#define IPV6_NEXTHOP 9
328#define IPV6_AUTHHDR 10
329#define IPV6_UNICAST_HOPS 16
330#define IPV6_MULTICAST_IF 17
331#define IPV6_MULTICAST_HOPS 18
332#define IPV6_MULTICAST_LOOP 19
333#define IPV6_JOIN_GROUP 20
334#define IPV6_LEAVE_GROUP 21
335#define IPV6_ROUTER_ALERT 22
336#define IPV6_MTU_DISCOVER 23
337#define IPV6_MTU 24
338#define IPV6_RECVERR 25
339#define IPV6_V6ONLY 26
340#define IPV6_JOIN_ANYCAST 27
341#define IPV6_LEAVE_ANYCAST 28
342#define IPV6_IPSEC_POLICY 34
343#define IPV6_XFRM_POLICY 35
344
345#define IPV6_RECVPKTINFO 49
346#define IPV6_PKTINFO 50
347#define IPV6_RECVHOPLIMIT 51
348#define IPV6_HOPLIMIT 52
349#define IPV6_RECVHOPOPTS 53
350#define IPV6_HOPOPTS 54
351#define IPV6_RTHDRDSTOPTS 55
352#define IPV6_RECVRTHDR 56
353#define IPV6_RTHDR 57
354#define IPV6_RECVDSTOPTS 58
355#define IPV6_DSTOPTS 59
Szabolcs Nagyc3504682014-05-30 14:15:48 +0200356#define IPV6_RECVPATHMTU 60
357#define IPV6_PATHMTU 61
358#define IPV6_DONTFRAG 62
Rich Felkerc8175662011-09-18 15:31:44 -0400359#define IPV6_RECVTCLASS 66
360#define IPV6_TCLASS 67
Szabolcs Nagyc3504682014-05-30 14:15:48 +0200361#define IPV6_ADDR_PREFERENCES 72
362#define IPV6_MINHOPCOUNT 73
363#define IPV6_ORIGDSTADDR 74
364#define IPV6_RECVORIGDSTADDR IPV6_ORIGDSTADDR
365#define IPV6_TRANSPARENT 75
366#define IPV6_UNICAST_IF 76
Rich Felkerc8175662011-09-18 15:31:44 -0400367
368#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
369#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
370#define IPV6_RXHOPOPTS IPV6_HOPOPTS
371#define IPV6_RXDSTOPTS IPV6_DSTOPTS
372
Rich Felkerc8175662011-09-18 15:31:44 -0400373#define IPV6_PMTUDISC_DONT 0
374#define IPV6_PMTUDISC_WANT 1
375#define IPV6_PMTUDISC_DO 2
376#define IPV6_PMTUDISC_PROBE 3
Szabolcs Nagyc3504682014-05-30 14:15:48 +0200377#define IPV6_PMTUDISC_INTERFACE 4
378#define IPV6_PMTUDISC_OMIT 5
379
380#define IPV6_PREFER_SRC_TMP 0x0001
381#define IPV6_PREFER_SRC_PUBLIC 0x0002
382#define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100
383#define IPV6_PREFER_SRC_COA 0x0004
384#define IPV6_PREFER_SRC_HOME 0x0400
385#define IPV6_PREFER_SRC_CGA 0x0008
386#define IPV6_PREFER_SRC_NONCGA 0x0800
Rich Felkerc8175662011-09-18 15:31:44 -0400387
Rich Felkerc8175662011-09-18 15:31:44 -0400388#define IPV6_RTHDR_LOOSE 0
389#define IPV6_RTHDR_STRICT 1
390
391#define IPV6_RTHDR_TYPE_0 0
392
Rich Felker3ed8c9f2011-11-10 20:40:06 -0500393#ifdef __cplusplus
394}
395#endif
396
Rich Felker0b44a032011-02-12 00:22:29 -0500397#endif