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