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 #ifndef LWRES_IPV6_H
13 #define LWRES_IPV6_H 1
14 
15 /*****
16  ***** Module Info
17  *****/
18 
19 /*! \file lwres/ipv6.h
20  * IPv6 definitions for systems which do not support IPv6.
21  */
22 
23 /***
24  *** Imports.
25  ***/
26 
27 #include <inttypes.h>
28 
29 #include <lwres/platform.h>
30 
31 /***
32  *** Types.
33  ***/
34 
35 /*% in6_addr structure */
36 struct in6_addr {
37 	union {
38 		uint8_t	_S6_u8[16];
39 		uint16_t	_S6_u16[8];
40 		uint32_t	_S6_u32[4];
41 	} _S6_un;
42 };
43 /*@{*/
44 /*% IP v6 types */
45 #define s6_addr		_S6_un._S6_u8
46 #define s6_addr8	_S6_un._S6_u8
47 #define s6_addr16	_S6_un._S6_u16
48 #define s6_addr32	_S6_un._S6_u32
49 /*@}*/
50 
51 #define IN6ADDR_ANY_INIT 	{{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
52 #define IN6ADDR_LOOPBACK_INIT 	{{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
53 
54 LIBLWRES_EXTERNAL_DATA extern const struct in6_addr in6addr_any;
55 LIBLWRES_EXTERNAL_DATA extern const struct in6_addr in6addr_loopback;
56 
57 /*% used in getaddrinfo.c and getnameinfo.c */
58 struct sockaddr_in6 {
59 #ifdef LWRES_PLATFORM_HAVESALEN
60 	uint8_t		sin6_len;
61 	uint8_t		sin6_family;
62 #else
63 	uint16_t		sin6_family;
64 #endif
65 	uint16_t		sin6_port;
66 	uint32_t		sin6_flowinfo;
67 	struct in6_addr		sin6_addr;
68 	uint32_t		sin6_scope_id;
69 };
70 
71 #ifdef LWRES_PLATFORM_HAVESALEN
72 #define SIN6_LEN 1
73 #endif
74 
75 /*% in6_pktinfo structure */
76 struct in6_pktinfo {
77 	struct in6_addr ipi6_addr;    /*%< src/dst IPv6 address */
78 	unsigned int    ipi6_ifindex; /*%< send/recv interface index */
79 };
80 
81 /*!
82  * Unspecified IPv6 address
83  */
84 #define IN6_IS_ADDR_UNSPECIFIED(a)      \
85 	(((a)->s6_addr32[0] == 0) &&    \
86 	 ((a)->s6_addr32[1] == 0) &&    \
87 	 ((a)->s6_addr32[2] == 0) &&    \
88 	 ((a)->s6_addr32[3] == 0))
89 
90 /*
91  * Loopback
92  */
93 #define IN6_IS_ADDR_LOOPBACK(a)         \
94 	(((a)->s6_addr32[0] == 0) &&    \
95 	 ((a)->s6_addr32[1] == 0) &&    \
96 	 ((a)->s6_addr32[2] == 0) &&    \
97 	 ((a)->s6_addr32[3] == htonl(1)))
98 
99 /*
100  * IPv4 compatible
101  */
102 #define IN6_IS_ADDR_V4COMPAT(a)         \
103 	(((a)->s6_addr32[0] == 0) &&    \
104 	 ((a)->s6_addr32[1] == 0) &&    \
105 	 ((a)->s6_addr32[2] == 0) &&    \
106 	 ((a)->s6_addr32[3] != 0) &&    \
107 	 ((a)->s6_addr32[3] != htonl(1)))
108 
109 /*
110  * Mapped
111  */
112 #define IN6_IS_ADDR_V4MAPPED(a)               \
113 	(((a)->s6_addr32[0] == 0) &&          \
114 	 ((a)->s6_addr32[1] == 0) &&          \
115 	 ((a)->s6_addr32[2] == htonl(0x0000ffff)))
116 
117 #endif /* LWRES_IPV6_H */
118