1 /*
2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
7  *
8  * See the COPYRIGHT file distributed with this work for additional
9  * information regarding copyright ownership.
10  */
11 
12 
13 #ifndef ISC_IPV6_H
14 #define ISC_IPV6_H 1
15 
16 /*****
17  ***** Module Info
18  *****/
19 
20 /*
21  * IPv6 definitions for systems which do not support IPv6.
22  *
23  * MP:
24  *	No impact.
25  *
26  * Reliability:
27  *	No anticipated impact.
28  *
29  * Resources:
30  *	N/A.
31  *
32  * Security:
33  *	No anticipated impact.
34  *
35  * Standards:
36  *	RFC2553.
37  */
38 
39 #if _MSC_VER < 1300
40 #define in6_addr in_addr6
41 #endif
42 
43 #ifndef IN6ADDR_ANY_INIT
44 #define IN6ADDR_ANY_INIT 	{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}
45 #endif
46 #ifndef IN6ADDR_LOOPBACK_INIT
47 #define IN6ADDR_LOOPBACK_INIT 	{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}
48 #endif
49 #ifndef IN6ADDR_V4MAPPED_INIT
50 #define IN6ADDR_V4MAPPED_INIT 	{{ 0,0,0,0,0,0,0,0,0,0,0xff,0xff,0,0,0,0 }}
51 #endif
52 
53 LIBISC_EXTERNAL_DATA extern const struct in6_addr isc_in6addr_any;
54 LIBISC_EXTERNAL_DATA extern const struct in6_addr isc_in6addr_loopback;
55 
56 /*
57  * Unspecified
58  */
59 #ifndef IN6_IS_ADDR_UNSPECIFIED
60 #define IN6_IS_ADDR_UNSPECIFIED(a) (\
61 *((u_long *)((a)->s6_addr)    ) == 0 && \
62 *((u_long *)((a)->s6_addr) + 1) == 0 && \
63 *((u_long *)((a)->s6_addr) + 2) == 0 && \
64 *((u_long *)((a)->s6_addr) + 3) == 0 \
65 )
66 #endif
67 
68 /*
69  * Loopback
70  */
71 #ifndef IN6_IS_ADDR_LOOPBACK
72 #define IN6_IS_ADDR_LOOPBACK(a) (\
73 *((u_long *)((a)->s6_addr)    ) == 0 && \
74 *((u_long *)((a)->s6_addr) + 1) == 0 && \
75 *((u_long *)((a)->s6_addr) + 2) == 0 && \
76 *((u_long *)((a)->s6_addr) + 3) == htonl(1) \
77 )
78 #endif
79 
80 /*
81  * IPv4 compatible
82  */
83 #define IN6_IS_ADDR_V4COMPAT(a)  (\
84 *((u_long *)((a)->s6_addr)    ) == 0 && \
85 *((u_long *)((a)->s6_addr) + 1) == 0 && \
86 *((u_long *)((a)->s6_addr) + 2) == 0 && \
87 *((u_long *)((a)->s6_addr) + 3) != 0 && \
88 *((u_long *)((a)->s6_addr) + 3) != htonl(1) \
89 )
90 
91 /*
92  * Mapped
93  */
94 #define IN6_IS_ADDR_V4MAPPED(a) (\
95 *((u_long *)((a)->s6_addr)    ) == 0 && \
96 *((u_long *)((a)->s6_addr) + 1) == 0 && \
97 *((u_long *)((a)->s6_addr) + 2) == htonl(0x0000ffff))
98 
99 /*
100  * Multicast
101  */
102 #define IN6_IS_ADDR_MULTICAST(a)	\
103 	((a)->s6_addr[0] == 0xffU)
104 
105 /*
106  * Unicast link / site local.
107  */
108 #ifndef IN6_IS_ADDR_LINKLOCAL
109 #define IN6_IS_ADDR_LINKLOCAL(a)	(\
110        ((a)->s6_addr[0] == 0xfe) && \
111        (((a)->s6_addr[1] & 0xc0) == 0x80))
112 #endif
113 
114 #ifndef IN6_IS_ADDR_SITELOCAL
115 #define IN6_IS_ADDR_SITELOCAL(a)	(\
116        ((a)->s6_addr[0] == 0xfe) && \
117        (((a)->s6_addr[1] & 0xc0) == 0xc0))
118 #endif
119 
120 #endif /* ISC_IPV6_H */
121