1 /*
2  * Copyright (C) 2004, 2005, 2007, 2011, 2012  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2002  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 /* $Id$ */
19 
20 #ifndef ISC_IPV6_H
21 #define ISC_IPV6_H 1
22 
23 /*****
24  ***** Module Info
25  *****/
26 
27 /*
28  * IPv6 definitions for systems which do not support IPv6.
29  *
30  * MP:
31  *	No impact.
32  *
33  * Reliability:
34  *	No anticipated impact.
35  *
36  * Resources:
37  *	N/A.
38  *
39  * Security:
40  *	No anticipated impact.
41  *
42  * Standards:
43  *	RFC2553.
44  */
45 
46 #if _MSC_VER < 1300
47 #define in6_addr in_addr6
48 #endif
49 
50 #ifndef IN6ADDR_ANY_INIT
51 #define IN6ADDR_ANY_INIT 	{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}
52 #endif
53 #ifndef IN6ADDR_LOOPBACK_INIT
54 #define IN6ADDR_LOOPBACK_INIT 	{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}
55 #endif
56 
57 LIBISC_EXTERNAL_DATA extern const struct in6_addr isc_net_in6addrany;
58 LIBISC_EXTERNAL_DATA extern const struct in6_addr isc_net_in6addrloop;
59 
60 /*
61  * Unspecified
62  */
63 #ifndef IN6_IS_ADDR_UNSPECIFIED
64 #define IN6_IS_ADDR_UNSPECIFIED(a) (\
65 *((u_long *)((a)->s6_addr)    ) == 0 && \
66 *((u_long *)((a)->s6_addr) + 1) == 0 && \
67 *((u_long *)((a)->s6_addr) + 2) == 0 && \
68 *((u_long *)((a)->s6_addr) + 3) == 0 \
69 )
70 #endif
71 
72 /*
73  * Loopback
74  */
75 #ifndef IN6_IS_ADDR_LOOPBACK
76 #define IN6_IS_ADDR_LOOPBACK(a) (\
77 *((u_long *)((a)->s6_addr)    ) == 0 && \
78 *((u_long *)((a)->s6_addr) + 1) == 0 && \
79 *((u_long *)((a)->s6_addr) + 2) == 0 && \
80 *((u_long *)((a)->s6_addr) + 3) == htonl(1) \
81 )
82 #endif
83 
84 /*
85  * IPv4 compatible
86  */
87 #define IN6_IS_ADDR_V4COMPAT(a)  (\
88 *((u_long *)((a)->s6_addr)    ) == 0 && \
89 *((u_long *)((a)->s6_addr) + 1) == 0 && \
90 *((u_long *)((a)->s6_addr) + 2) == 0 && \
91 *((u_long *)((a)->s6_addr) + 3) != 0 && \
92 *((u_long *)((a)->s6_addr) + 3) != htonl(1) \
93 )
94 
95 /*
96  * Mapped
97  */
98 #define IN6_IS_ADDR_V4MAPPED(a) (\
99 *((u_long *)((a)->s6_addr)    ) == 0 && \
100 *((u_long *)((a)->s6_addr) + 1) == 0 && \
101 *((u_long *)((a)->s6_addr) + 2) == htonl(0x0000ffff))
102 
103 /*
104  * Multicast
105  */
106 #define IN6_IS_ADDR_MULTICAST(a)	\
107 	((a)->s6_addr[0] == 0xffU)
108 
109 /*
110  * Unicast link / site local.
111  */
112 #ifndef IN6_IS_ADDR_LINKLOCAL
113 #define IN6_IS_ADDR_LINKLOCAL(a)	(\
114 	((a)->s6_addr[0] == 0xfe) && \
115 	(((a)->s6_addr[1] & 0xc0) == 0x80))
116 #endif
117 
118 #ifndef IN6_IS_ADDR_SITELOCAL
119 #define IN6_IS_ADDR_SITELOCAL(a)	(\
120 	((a)->s6_addr[0] == 0xfe) && \
121 	(((a)->s6_addr[1] & 0xc0) == 0xc0))
122 #endif
123 
124 #endif /* ISC_IPV6_H */
125