xref: /haiku/headers/posix/netinet6/in6.h (revision 922e7ba1f3228e6f28db69b0ded8f86eb32dea17)
1 /*
2  * Copyright 2006-2010 Haiku Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _NETINET6_IN6_H_
6 #define _NETINET6_IN6_H_
7 
8 
9 #include <sys/types.h>
10 #include <stdint.h>
11 
12 
13 struct in6_addr {
14 	uint8_t		s6_addr[16];
15 };
16 
17 /* IP Version 6 socket address. */
18 struct sockaddr_in6 {
19 	uint8_t		sin6_len;
20 	uint8_t		sin6_family;
21 	uint16_t	sin6_port;
22 	uint32_t	sin6_flowinfo;
23 	struct in6_addr	sin6_addr;
24 	uint32_t	sin6_scope_id;
25 };
26 
27 
28 #define IN6ADDR_ANY_INIT {{ \
29 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
30 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}
31 #define IN6ADDR_LOOPBACK_INIT {{ \
32 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
33 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}
34 
35 extern const struct in6_addr in6addr_any;
36 extern const struct in6_addr in6addr_loopback;
37 
38 
39 struct ipv6_mreq {
40 	struct in6_addr ipv6mr_multiaddr;
41 	unsigned	ipv6mr_interface;
42 };
43 
44 
45 struct in6_pktinfo {
46 	struct in6_addr ipi6_addr;      /* src/dst IPv6 address */
47 	unsigned int    ipi6_ifindex;   /* send/recv interface index */
48 };
49 
50 
51 /* Non-standard helper defines (same as in FreeBSD, though) */
52 #define __IPV6_ADDR_SCOPE_NODELOCAL			0x01
53 #define __IPV6_ADDR_SCOPE_INTFACELOCAL		0x01
54 #define __IPV6_ADDR_SCOPE_LINKLOCAL			0x02
55 #define __IPV6_ADDR_SCOPE_SITELOCAL			0x05
56 #define __IPV6_ADDR_SCOPE_ORGLOCAL			0x08
57 #define __IPV6_ADDR_SCOPE_GLOBAL			0x0e
58 
59 #define __IPV6_ADDR_MC_SCOPE(a)				((a)->s6_addr[1] & 0x0f)
60 
61 
62 #define IN6_IS_ADDR_UNSPECIFIED(a) \
63 	(!memcmp((a)->s6_addr, in6addr_any.s6_addr, sizeof(struct in6_addr)))
64 
65 #define IN6_IS_ADDR_LOOPBACK(a) \
66 	(!memcmp((a)->s6_addr, in6addr_loopback.s6_addr, sizeof(struct in6_addr)))
67 
68 #define IN6_IS_ADDR_MULTICAST(a) \
69 	((a)->s6_addr[0] == 0xff)
70 
71 #define IN6_IS_ADDR_LINKLOCAL(a) \
72 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
73 
74 #define IN6_IS_ADDR_SITELOCAL(a) \
75 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
76 
77 #define IN6_IS_ADDR_V4MAPPED(a) \
78 	((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 \
79 	&& (a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 \
80 	&& (a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 \
81 	&& (a)->s6_addr[6] == 0x00 && (a)->s6_addr[9] == 0x00 \
82 	&& (a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 \
83 	&& (a)->s6_addr[10] == 0xff && (a)->s6_addr[11] == 0xff)
84 
85 #define IN6_IS_ADDR_V4COMPAT(a) \
86 	((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 \
87 	&& (a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 \
88 	&& (a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 \
89 	&& (a)->s6_addr[6] == 0x00 && (a)->s6_addr[9] == 0x00 \
90 	&& (a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 \
91 	&& (a)->s6_addr[10] == 0x00 && (a)->s6_addr[11] == 0x01)
92 
93 #define IN6_IS_ADDR_MC_NODELOCAL(a) \
94 	(IN6_IS_ADDR_MULTICAST(a) && __IPV6_ADDR_MC_SCOPE(a) \
95 		== __IPV6_ADDR_SCOPE_NODELOCAL)
96 
97 #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
98 	(IN6_IS_ADDR_MULTICAST(a) && __IPV6_ADDR_MC_SCOPE(a) \
99 		== __IPV6_ADDR_SCOPE_LINKLOCAL)
100 
101 #define IN6_IS_ADDR_MC_SITELOCAL(a) \
102 	(IN6_IS_ADDR_MULTICAST(a) && __IPV6_ADDR_MC_SCOPE(a) \
103 		== __IPV6_ADDR_SCOPE_SITELOCAL)
104 
105 #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
106 	(IN6_IS_ADDR_MULTICAST(a) && __IPV6_ADDR_MC_SCOPE(a) \
107 		== __IPV6_ADDR_SCOPE_ORGLOCAL)
108 
109 #define IN6_IS_ADDR_MC_GLOBAL(a) \
110 	(IN6_IS_ADDR_MULTICAST(a) && __IPV6_ADDR_MC_SCOPE(a) \
111 		== __IPV6_ADDR_SCOPE_GLOBAL)
112 
113 /* From RFC 2292 (Advanced Sockets API for IPv6) */
114 #define IN6_ARE_ADDR_EQUAL(a, b) \
115 	(!memcmp((a)->s6_addr, (b)->s6_addr, sizeof(struct in6_addr)))
116 
117 /* maximal length of the string representation of an IPv6 address */
118 #define INET6_ADDRSTRLEN				46
119 
120 
121 #endif	/* _NETINET6_IN6_H_ */
122