1 /*
2  * in6.h -- various IPv6 related definitions and macros
3  */
4 /*
5  * Copyright (C) 2010 - 2021 Eggheads Development Team
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20  */
21 
22 #ifdef IPV6
23 
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <netinet/in.h>
27 
28 
29 #ifndef PF_INET6
30 #  define PF_INET6 PF_MAX
31 #endif
32 
33 #ifndef AF_INET6
34 #  define AF_INET6 PF_INET6
35 #endif
36 
37 #ifndef HAVE_STRUCT_IN6_ADDR
38 struct in6_addr {
39   union {
40     uint8_t	__u6_addr8[16];
41     uint16_t	__u6_addr16[8];
42     uint32_t	__u6_addr32[4];
43   } __u6_addr;
44 #define	s6_addr	__u6_addr.__u6_addr8
45 };
46 #endif
47 
48 #ifndef HAVE_STRUCT_SOCKADDR_IN6
49 struct sockaddr_in6 {
50   uint16_t 	  sin6_family;
51   uint16_t 	  sin6_port;
52   uint32_t 	  sin6_flowinfo;
53   struct in6_addr sin6_addr;
54   uint32_t       sin6_scope_id;
55 };
56 #endif
57 
58 #ifndef INET6_ADDRSTRLEN
59 #  define INET6_ADDRSTRLEN 46
60 #endif
61 
62 #ifndef IN6ADDR_ANY_INIT
63 #  define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
64 #endif
65 
66 #ifndef IN6ADDR_LOOPBACK_INIT
67 #  define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
68 #endif
69 
70 #ifndef HAVE_IN6ADDR_ANY
71 extern const struct in6_addr in6addr_any;
72 #endif
73 
74 #ifndef HAVE_IN6ADDR_LOOPBACK
75 extern const struct in6_addr in6addr_loopback;
76 #endif
77 
78 #ifndef IN6_IS_ADDR_UNSPECIFIED
79 # define IN6_IS_ADDR_UNSPECIFIED(a) \
80   (((const uint32_t *) (a))[0] == 0                                   \
81    && ((const uint32_t *) (a))[1] == 0                                \
82    && ((const uint32_t *) (a))[2] == 0                                \
83    && ((const uint32_t *) (a))[3] == 0)
84 #endif
85 
86 #ifndef IN6_IS_ADDR_LOOPBACK
87 # define IN6_IS_ADDR_LOOPBACK(a) \
88   (((const uint32_t *) (a))[0] == 0                                   \
89    && ((const uint32_t *) (a))[1] == 0                                \
90    && ((const uint32_t *) (a))[2] == 0                                \
91    && ((const uint32_t *) (a))[3] == htonl (1))
92 #endif
93 
94 #ifndef IN6_IS_ADDR_V4MAPPED
95 # define IN6_IS_ADDR_V4MAPPED(a) \
96   ((((const uint32_t *) (a))[0] == 0)                                 \
97    && (((const uint32_t *) (a))[1] == 0)                              \
98    && (((const uint32_t *) (a))[2] == htonl (0xffff)))
99 #endif
100 
101 #ifndef IN6_ARE_ADDR_EQUAL
102 # define IN6_ARE_ADDR_EQUAL(a,b) \
103   ((((const uint32_t *) (a))[0] == ((const uint32_t *) (b))[0])     \
104    && (((const uint32_t *) (a))[1] == ((const uint32_t *) (b))[1])  \
105    && (((const uint32_t *) (a))[2] == ((const uint32_t *) (b))[2])  \
106    && (((const uint32_t *) (a))[3] == ((const uint32_t *) (b))[3]))
107 #endif
108 
109 #endif /* IPV6 */
110