xref: /haiku/headers/posix/netinet6/in6.h (revision 71452e98334eaac603bf542d159e24788a46bebb)
1 /*
2  * Copyright 2006-2012 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 #define IN6ADDR_NODELOCAL_ALLNODES_INIT {{ \
35 	0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
36 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}
37 #define IN6ADDR_LINKLOCAL_ALLNODES_INIT {{ \
38 	0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
39 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}
40 #define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT {{ \
41 	0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
42 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}
43 
44 extern const struct in6_addr in6addr_any;
45 extern const struct in6_addr in6addr_loopback;
46 
47 
48 struct ipv6_mreq {
49 	struct in6_addr ipv6mr_multiaddr;
50 	unsigned	ipv6mr_interface;
51 };
52 
53 
54 struct in6_pktinfo {
55 	struct in6_addr ipi6_addr;      /* src/dst IPv6 address */
56 	unsigned int    ipi6_ifindex;   /* send/recv interface index */
57 };
58 
59 
60 /* Non-standard helper defines (same as in FreeBSD, though) */
61 #define __IPV6_ADDR_SCOPE_NODELOCAL			0x01
62 #define __IPV6_ADDR_SCOPE_INTFACELOCAL		0x01
63 #define __IPV6_ADDR_SCOPE_LINKLOCAL			0x02
64 #define __IPV6_ADDR_SCOPE_SITELOCAL			0x05
65 #define __IPV6_ADDR_SCOPE_ORGLOCAL			0x08
66 #define __IPV6_ADDR_SCOPE_GLOBAL			0x0e
67 
68 #define __IPV6_ADDR_MC_SCOPE(a)				((a)->s6_addr[1] & 0x0f)
69 
70 
71 #define IN6_IS_ADDR_UNSPECIFIED(a) \
72 	(!memcmp((a)->s6_addr, in6addr_any.s6_addr, sizeof(struct in6_addr)))
73 
74 #define IN6_IS_ADDR_LOOPBACK(a) \
75 	(!memcmp((a)->s6_addr, in6addr_loopback.s6_addr, sizeof(struct in6_addr)))
76 
77 #define IN6_IS_ADDR_MULTICAST(a) \
78 	((a)->s6_addr[0] == 0xff)
79 
80 #define IN6_IS_ADDR_LINKLOCAL(a) \
81 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
82 
83 #define IN6_IS_ADDR_SITELOCAL(a) \
84 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
85 
86 #define IN6_IS_ADDR_V4MAPPED(a) \
87 	((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 \
88 	&& (a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 \
89 	&& (a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 \
90 	&& (a)->s6_addr[6] == 0x00 && (a)->s6_addr[9] == 0x00 \
91 	&& (a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 \
92 	&& (a)->s6_addr[10] == 0xff && (a)->s6_addr[11] == 0xff)
93 
94 #define IN6_IS_ADDR_V4COMPAT(a) \
95 	((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 \
96 	&& (a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 \
97 	&& (a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 \
98 	&& (a)->s6_addr[6] == 0x00 && (a)->s6_addr[9] == 0x00 \
99 	&& (a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 \
100 	&& (a)->s6_addr[10] == 0x00 && (a)->s6_addr[11] == 0x01)
101 
102 #define IN6_IS_ADDR_MC_NODELOCAL(a) \
103 	(IN6_IS_ADDR_MULTICAST(a) && __IPV6_ADDR_MC_SCOPE(a) \
104 		== __IPV6_ADDR_SCOPE_NODELOCAL)
105 
106 #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
107 	(IN6_IS_ADDR_MULTICAST(a) && __IPV6_ADDR_MC_SCOPE(a) \
108 		== __IPV6_ADDR_SCOPE_LINKLOCAL)
109 
110 #define IN6_IS_ADDR_MC_SITELOCAL(a) \
111 	(IN6_IS_ADDR_MULTICAST(a) && __IPV6_ADDR_MC_SCOPE(a) \
112 		== __IPV6_ADDR_SCOPE_SITELOCAL)
113 
114 #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
115 	(IN6_IS_ADDR_MULTICAST(a) && __IPV6_ADDR_MC_SCOPE(a) \
116 		== __IPV6_ADDR_SCOPE_ORGLOCAL)
117 
118 #define IN6_IS_ADDR_MC_GLOBAL(a) \
119 	(IN6_IS_ADDR_MULTICAST(a) && __IPV6_ADDR_MC_SCOPE(a) \
120 		== __IPV6_ADDR_SCOPE_GLOBAL)
121 
122 /* From RFC 2292 (Advanced Sockets API for IPv6) */
123 #define IN6_ARE_ADDR_EQUAL(a, b) \
124 	(!memcmp((a)->s6_addr, (b)->s6_addr, sizeof(struct in6_addr)))
125 
126 /* maximal length of the string representation of an IPv6 address */
127 #define INET6_ADDRSTRLEN				46
128 
129 
130 #endif	/* _NETINET6_IN6_H_ */
131