2 * Copyright (C) 1999-2001 Internet Software Consortium.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
9 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
10 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
11 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
13 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
14 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: net.h,v 1.34 2002/04/03 06:38:38 marka Exp $ */
28 * Basic Networking Types
30 * This module is responsible for defining the following basic networking
41 * It ensures that the AF_ and PF_ macros are defined.
43 * It declares ntoh[sl]() and hton[sl]().
45 * It declares inet_aton(), inet_ntop(), and inet_pton().
47 * It ensures that INADDR_LOOPBACK, INADDR_ANY, IN6ADDR_ANY_INIT,
48 * in6addr_any, and in6addr_loopback are available.
50 * It ensures that IN_MULTICAST() is available to check for multicast
57 * No anticipated impact.
63 * No anticipated impact.
73 #include <isc/platform.h>
75 #include <sys/types.h>
76 #include <sys/socket.h> /* Contractual promise. */
78 #include <netinet/in.h> /* Contractual promise. */
79 #include <arpa/inet.h> /* Contractual promise. */
80 #ifdef ISC_PLATFORM_NEEDNETINETIN6H
81 #include <netinet/in6.h> /* Required on UnixWare. */
83 #ifdef ISC_PLATFORM_NEEDNETINET6IN6H
84 #include <netinet6/in6.h> /* Required on BSD/OS for in6_pktinfo. */
87 #ifndef ISC_PLATFORM_HAVEIPV6
88 #include <isc/ipv6.h> /* Contractual promise. */
92 #include <isc/types.h>
94 #ifdef ISC_PLATFORM_HAVEINADDR6
95 #define in6_addr in_addr6 /* Required for pre RFC2133 implementations. */
98 #ifdef ISC_PLATFORM_HAVEIPV6
100 * Required for some pre RFC2133 implementations.
101 * IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT were added in
102 * draft-ietf-ipngwg-bsd-api-04.txt or draft-ietf-ipngwg-bsd-api-05.txt.
103 * If 's6_addr' is defined then assume that there is a union and three
104 * levels otherwise assume two levels required.
106 #ifndef IN6ADDR_ANY_INIT
108 #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
110 #define IN6ADDR_ANY_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } }
114 #ifndef IN6ADDR_LOOPBACK_INIT
116 #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
118 #define IN6ADDR_LOOPBACK_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } }
122 #ifndef IN6_IS_ADDR_V4MAPPED
123 #define IN6_IS_ADDR_V4MAPPED(x) \
124 (memcmp((x)->s6_addr, in6addr_any.s6_addr, 10) == 0 && \
125 (x)->s6_addr[10] == 0xff && (x)->s6_addr[11] == 0xff)
128 #ifndef IN6_IS_ADDR_V4COMPAT
129 #define IN6_IS_ADDR_V4COMPAT(x) \
130 (memcmp((x)->s6_addr, in6addr_any.s6_addr, 12) == 0 && \
131 ((x)->s6_addr[12] != 0 || (x)->s6_addr[13] != 0 || \
132 (x)->s6_addr[14] != 0 || \
133 ((x)->s6_addr[15] != 0 && (x)->s6_addr[15] != 1)))
136 #ifndef IN6_IS_ADDR_MULTICAST
137 #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
140 #ifndef IN6_IS_ADDR_LINKLOCAL
141 #define IN6_IS_ADDR_LINKLOCAL(a) \
142 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
145 #ifndef IN6_IS_ADDR_SITELOCAL
146 #define IN6_IS_ADDR_SITELOCAL(a) \
147 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
151 #ifndef IN6_IS_ADDR_LOOPBACK
152 #define IN6_IS_ADDR_LOOPBACK(x) \
153 (memcmp((x)->s6_addr, in6addr_loopback.s6_addr, 16) == 0)
162 #define PF_INET6 AF_INET6
165 #ifndef INADDR_LOOPBACK
166 #define INADDR_LOOPBACK 0x7f000001UL
170 #ifndef ISC_PLATFORM_HAVEIN6PKTINFO
172 struct in6_addr ipi6_addr; /* src/dst IPv6 address */
173 unsigned int ipi6_ifindex; /* send/recv interface index */
179 * Cope with a missing in6addr_any and in6addr_loopback.
181 #if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRANY)
182 extern const struct in6_addr isc_net_in6addrany;
183 #define in6addr_any isc_net_in6addrany
186 #if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRLOOPBACK)
187 extern const struct in6_addr isc_net_in6addrloop;
188 #define in6addr_loopback isc_net_in6addrloop
192 * Fix UnixWare 7.1.1's broken IN6_IS_ADDR_* definitions.
194 #ifdef ISC_PLATFORM_FIXIN6ISADDR
195 #undef IN6_IS_ADDR_GEOGRAPHIC
196 #define IN6_IS_ADDR_GEOGRAPHIC(a) (((a)->S6_un.S6_l[0] & 0xE0) == 0x80)
197 #undef IN6_IS_ADDR_IPX
198 #define IN6_IS_ADDR_IPX(a) (((a)->S6_un.S6_l[0] & 0xFE) == 0x04)
199 #undef IN6_IS_ADDR_LINKLOCAL
200 #define IN6_IS_ADDR_LINKLOCAL(a) (((a)->S6_un.S6_l[0] & 0xC0FF) == 0x80FE)
201 #undef IN6_IS_ADDR_MULTICAST
202 #define IN6_IS_ADDR_MULTICAST(a) (((a)->S6_un.S6_l[0] & 0xFF) == 0xFF)
203 #undef IN6_IS_ADDR_NSAP
204 #define IN6_IS_ADDR_NSAP(a) (((a)->S6_un.S6_l[0] & 0xFE) == 0x02)
205 #undef IN6_IS_ADDR_PROVIDER
206 #define IN6_IS_ADDR_PROVIDER(a) (((a)->S6_un.S6_l[0] & 0xE0) == 0x40)
207 #undef IN6_IS_ADDR_SITELOCAL
208 #define IN6_IS_ADDR_SITELOCAL(a) (((a)->S6_un.S6_l[0] & 0xC0FF) == 0xC0FE)
209 #endif /* ISC_PLATFORM_FIXIN6ISADDR */
212 * Ensure type in_port_t is defined.
214 #ifdef ISC_PLATFORM_NEEDPORTT
215 typedef isc_uint16_t in_port_t;
219 * If this system does not have MSG_TRUNC (as returned from recvmsg())
220 * ISC_PLATFORM_RECVOVERFLOW will be defined. This will enable the MSG_TRUNC
221 * faking code in socket.c.
224 #define ISC_PLATFORM_RECVOVERFLOW
227 #define ISC__IPADDR(x) ((isc_uint32_t)htonl((isc_uint32_t)(x)))
229 #define ISC_IPADDR_ISMULTICAST(i) \
230 (((isc_uint32_t)(i) & ISC__IPADDR(0xf0000000)) \
231 == ISC__IPADDR(0xe0000000))
240 isc_net_probeipv4(void);
242 * Check if the system's kernel supports IPv4.
246 * ISC_R_SUCCESS IPv4 is supported.
247 * ISC_R_NOTFOUND IPv4 is not supported.
252 isc_net_probeipv6(void);
254 * Check if the system's kernel supports IPv6.
258 * ISC_R_SUCCESS IPv6 is supported.
259 * ISC_R_NOTFOUND IPv6 is not supported.
264 isc_net_ntop(int af, const void *src, char *dst, size_t size);
265 #ifdef ISC_PLATFORM_NEEDNTOP
266 #define inet_ntop isc_net_ntop
270 isc_net_pton(int af, const char *src, void *dst);
271 #ifdef ISC_PLATFORM_NEEDPTON
273 #define inet_pton isc_net_pton
277 isc_net_aton(const char *cp, struct in_addr *addr);
278 #ifdef ISC_PLATFORM_NEEDATON
279 #define inet_aton isc_net_aton
284 #endif /* ISC_NET_H */