1258945Sroberto/*
2258945Sroberto * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
3258945Sroberto * Copyright (C) 1999-2002  Internet Software Consortium.
4258945Sroberto *
5258945Sroberto * Permission to use, copy, modify, and/or distribute this software for any
6258945Sroberto * purpose with or without fee is hereby granted, provided that the above
7258945Sroberto * copyright notice and this permission notice appear in all copies.
8258945Sroberto *
9258945Sroberto * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10258945Sroberto * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11258945Sroberto * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12258945Sroberto * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13258945Sroberto * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14258945Sroberto * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15258945Sroberto * PERFORMANCE OF THIS SOFTWARE.
16258945Sroberto */
17258945Sroberto
18258945Sroberto/* $Id: ipv6.h,v 1.24 2007/06/19 23:47:18 tbox Exp $ */
19258945Sroberto
20258945Sroberto#ifndef ISC_IPV6_H
21258945Sroberto#define ISC_IPV6_H 1
22258945Sroberto
23258945Sroberto/*!
24258945Sroberto * Also define LWRES_IPV6_H to keep it from being included if liblwres is
25258945Sroberto * being used, or redefinition errors will occur.
26258945Sroberto */
27258945Sroberto#define LWRES_IPV6_H 1
28258945Sroberto
29258945Sroberto/*****
30258945Sroberto ***** Module Info
31258945Sroberto *****/
32258945Sroberto
33258945Sroberto/*! \file isc/ipv6.h
34258945Sroberto * \brief IPv6 definitions for systems which do not support IPv6.
35258945Sroberto *
36258945Sroberto * \li MP:
37258945Sroberto *	No impact.
38258945Sroberto *
39258945Sroberto * \li Reliability:
40258945Sroberto *	No anticipated impact.
41258945Sroberto *
42258945Sroberto * \li Resources:
43258945Sroberto *	N/A.
44258945Sroberto *
45258945Sroberto * \li Security:
46258945Sroberto *	No anticipated impact.
47258945Sroberto *
48258945Sroberto * \li Standards:
49258945Sroberto *	RFC2553.
50258945Sroberto */
51258945Sroberto
52258945Sroberto/***
53258945Sroberto *** Imports.
54258945Sroberto ***/
55258945Sroberto
56258945Sroberto#include <isc/int.h>
57258945Sroberto#include <isc/platform.h>
58258945Sroberto
59258945Sroberto/***
60258945Sroberto *** Types.
61258945Sroberto ***/
62258945Sroberto
63258945Srobertostruct in6_addr {
64258945Sroberto        union {
65258945Sroberto		isc_uint8_t	_S6_u8[16];
66258945Sroberto		isc_uint16_t	_S6_u16[8];
67258945Sroberto		isc_uint32_t	_S6_u32[4];
68258945Sroberto        } _S6_un;
69258945Sroberto};
70258945Sroberto#define s6_addr		_S6_un._S6_u8
71258945Sroberto#define s6_addr8	_S6_un._S6_u8
72258945Sroberto#define s6_addr16	_S6_un._S6_u16
73258945Sroberto#define s6_addr32	_S6_un._S6_u32
74258945Sroberto
75258945Sroberto#define IN6ADDR_ANY_INIT 	{{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
76258945Sroberto#define IN6ADDR_LOOPBACK_INIT 	{{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
77258945Sroberto
78258945SrobertoLIBISC_EXTERNAL_DATA extern const struct in6_addr in6addr_any;
79258945SrobertoLIBISC_EXTERNAL_DATA extern const struct in6_addr in6addr_loopback;
80258945Sroberto
81258945Srobertostruct sockaddr_in6 {
82258945Sroberto#ifdef ISC_PLATFORM_HAVESALEN
83258945Sroberto	isc_uint8_t		sin6_len;
84258945Sroberto	isc_uint8_t		sin6_family;
85258945Sroberto#else
86258945Sroberto	isc_uint16_t		sin6_family;
87258945Sroberto#endif
88258945Sroberto	isc_uint16_t		sin6_port;
89258945Sroberto	isc_uint32_t		sin6_flowinfo;
90258945Sroberto	struct in6_addr		sin6_addr;
91258945Sroberto	isc_uint32_t		sin6_scope_id;
92258945Sroberto};
93258945Sroberto
94258945Sroberto#ifdef ISC_PLATFORM_HAVESALEN
95258945Sroberto#define SIN6_LEN 1
96258945Sroberto#endif
97258945Sroberto
98258945Sroberto/*%
99258945Sroberto * Unspecified
100258945Sroberto */
101258945Sroberto#define IN6_IS_ADDR_UNSPECIFIED(a)      \
102258945Sroberto        (((a)->s6_addr32[0] == 0) &&    \
103258945Sroberto         ((a)->s6_addr32[1] == 0) &&    \
104258945Sroberto         ((a)->s6_addr32[2] == 0) &&    \
105258945Sroberto         ((a)->s6_addr32[3] == 0))
106258945Sroberto
107258945Sroberto/*%
108258945Sroberto * Loopback
109258945Sroberto */
110258945Sroberto#define IN6_IS_ADDR_LOOPBACK(a)         \
111258945Sroberto        (((a)->s6_addr32[0] == 0) &&    \
112258945Sroberto         ((a)->s6_addr32[1] == 0) &&    \
113258945Sroberto         ((a)->s6_addr32[2] == 0) &&    \
114258945Sroberto         ((a)->s6_addr32[3] == htonl(1)))
115258945Sroberto
116258945Sroberto/*%
117258945Sroberto * IPv4 compatible
118258945Sroberto */
119258945Sroberto#define IN6_IS_ADDR_V4COMPAT(a)         \
120258945Sroberto        (((a)->s6_addr32[0] == 0) &&    \
121258945Sroberto         ((a)->s6_addr32[1] == 0) &&    \
122258945Sroberto         ((a)->s6_addr32[2] == 0) &&    \
123258945Sroberto         ((a)->s6_addr32[3] != 0) &&    \
124258945Sroberto         ((a)->s6_addr32[3] != htonl(1)))
125258945Sroberto
126258945Sroberto/*%
127258945Sroberto * Mapped
128258945Sroberto */
129258945Sroberto#define IN6_IS_ADDR_V4MAPPED(a)               \
130258945Sroberto        (((a)->s6_addr32[0] == 0) &&          \
131258945Sroberto         ((a)->s6_addr32[1] == 0) &&          \
132258945Sroberto         ((a)->s6_addr32[2] == htonl(0x0000ffff)))
133258945Sroberto
134258945Sroberto/*%
135258945Sroberto * Multicast
136258945Sroberto */
137258945Sroberto#define IN6_IS_ADDR_MULTICAST(a)	\
138258945Sroberto	((a)->s6_addr8[0] == 0xffU)
139258945Sroberto
140258945Sroberto/*%
141258945Sroberto * Unicast link / site local.
142258945Sroberto */
143258945Sroberto#define IN6_IS_ADDR_LINKLOCAL(a)	\
144258945Sroberto	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
145258945Sroberto#define IN6_IS_ADDR_SITELOCAL(a)	\
146258945Sroberto	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
147258945Sroberto
148258945Sroberto#endif /* ISC_IPV6_H */
149