1 /* $NetBSD: net.h,v 1.2 2003/12/04 16:23:36 drochner Exp $ */
4 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: net.h,v 1.31.2.2.10.8 2004/04/29 01:31:23 marka Exp */
30 * Basic Networking Types
32 * This module is responsible for defining the following basic networking
43 * It ensures that the AF_ and PF_ macros are defined.
45 * It declares ntoh[sl]() and hton[sl]().
47 * It declares inet_aton(), inet_ntop(), and inet_pton().
49 * It ensures that INADDR_LOOPBACK, INADDR_ANY, IN6ADDR_ANY_INIT,
50 * in6addr_any, and in6addr_loopback are available.
52 * It ensures that IN_MULTICAST() is available to check for multicast
59 * No anticipated impact.
65 * No anticipated impact.
75 #include <isc/platform.h>
77 #include <sys/types.h>
78 #include <sys/socket.h> /* Contractual promise. */
82 #include <netinet/in.h> /* Contractual promise. */
83 #include <arpa/inet.h> /* Contractual promise. */
84 #ifdef ISC_PLATFORM_NEEDNETINETIN6H
85 #include <netinet/in6.h> /* Required on UnixWare. */
87 #ifdef ISC_PLATFORM_NEEDNETINET6IN6H
88 #include <netinet6/in6.h> /* Required on BSD/OS for in6_pktinfo. */
91 #ifndef ISC_PLATFORM_HAVEIPV6
92 #include <isc/ipv6.h> /* Contractual promise. */
96 #include <isc/types.h>
98 #ifdef ISC_PLATFORM_HAVEINADDR6
99 #define in6_addr in_addr6 /* Required for pre RFC2133 implementations. */
102 #ifdef ISC_PLATFORM_HAVEIPV6
104 * Required for some pre RFC2133 implementations.
105 * IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT were added in
106 * draft-ietf-ipngwg-bsd-api-04.txt or draft-ietf-ipngwg-bsd-api-05.txt.
107 * If 's6_addr' is defined then assume that there is a union and three
108 * levels otherwise assume two levels required.
110 #ifndef IN6ADDR_ANY_INIT
112 #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
114 #define IN6ADDR_ANY_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } }
118 #ifndef IN6ADDR_LOOPBACK_INIT
120 #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
122 #define IN6ADDR_LOOPBACK_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } }
126 #ifndef IN6_IS_ADDR_V4MAPPED
127 #define IN6_IS_ADDR_V4MAPPED(x) \
128 (memcmp((x)->s6_addr, in6addr_any.s6_addr, 10) == 0 && \
129 (x)->s6_addr[10] == 0xff && (x)->s6_addr[11] == 0xff)
132 #ifndef IN6_IS_ADDR_V4COMPAT
133 #define IN6_IS_ADDR_V4COMPAT(x) \
134 (memcmp((x)->s6_addr, in6addr_any.s6_addr, 12) == 0 && \
135 ((x)->s6_addr[12] != 0 || (x)->s6_addr[13] != 0 || \
136 (x)->s6_addr[14] != 0 || \
137 ((x)->s6_addr[15] != 0 && (x)->s6_addr[15] != 1)))
140 #ifndef IN6_IS_ADDR_MULTICAST
141 #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
144 #ifndef IN6_IS_ADDR_LINKLOCAL
145 #define IN6_IS_ADDR_LINKLOCAL(a) \
146 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
149 #ifndef IN6_IS_ADDR_SITELOCAL
150 #define IN6_IS_ADDR_SITELOCAL(a) \
151 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
155 #ifndef IN6_IS_ADDR_LOOPBACK
156 #define IN6_IS_ADDR_LOOPBACK(x) \
157 (memcmp((x)->s6_addr, in6addr_loopback.s6_addr, 16) == 0)
166 #define PF_INET6 AF_INET6
169 #ifndef INADDR_LOOPBACK
170 #define INADDR_LOOPBACK 0x7f000001UL
174 #ifndef ISC_PLATFORM_HAVEIN6PKTINFO
176 struct in6_addr ipi6_addr
; /* src/dst IPv6 address */
177 unsigned int ipi6_ifindex
; /* send/recv interface index */
183 * Cope with a missing in6addr_any and in6addr_loopback.
185 #if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRANY)
186 extern const struct in6_addr isc_net_in6addrany
;
187 #define in6addr_any isc_net_in6addrany
190 #if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRLOOPBACK)
191 extern const struct in6_addr isc_net_in6addrloop
;
192 #define in6addr_loopback isc_net_in6addrloop
196 * Fix UnixWare 7.1.1's broken IN6_IS_ADDR_* definitions.
198 #ifdef ISC_PLATFORM_FIXIN6ISADDR
199 #undef IN6_IS_ADDR_GEOGRAPHIC
200 #define IN6_IS_ADDR_GEOGRAPHIC(a) (((a)->S6_un.S6_l[0] & 0xE0) == 0x80)
201 #undef IN6_IS_ADDR_IPX
202 #define IN6_IS_ADDR_IPX(a) (((a)->S6_un.S6_l[0] & 0xFE) == 0x04)
203 #undef IN6_IS_ADDR_LINKLOCAL
204 #define IN6_IS_ADDR_LINKLOCAL(a) (((a)->S6_un.S6_l[0] & 0xC0FF) == 0x80FE)
205 #undef IN6_IS_ADDR_MULTICAST
206 #define IN6_IS_ADDR_MULTICAST(a) (((a)->S6_un.S6_l[0] & 0xFF) == 0xFF)
207 #undef IN6_IS_ADDR_NSAP
208 #define IN6_IS_ADDR_NSAP(a) (((a)->S6_un.S6_l[0] & 0xFE) == 0x02)
209 #undef IN6_IS_ADDR_PROVIDER
210 #define IN6_IS_ADDR_PROVIDER(a) (((a)->S6_un.S6_l[0] & 0xE0) == 0x40)
211 #undef IN6_IS_ADDR_SITELOCAL
212 #define IN6_IS_ADDR_SITELOCAL(a) (((a)->S6_un.S6_l[0] & 0xC0FF) == 0xC0FE)
213 #endif /* ISC_PLATFORM_FIXIN6ISADDR */
216 * Ensure type in_port_t is defined.
218 #ifdef ISC_PLATFORM_NEEDPORTT
219 typedef isc_uint16_t in_port_t
;
223 * If this system does not have MSG_TRUNC (as returned from recvmsg())
224 * ISC_PLATFORM_RECVOVERFLOW will be defined. This will enable the MSG_TRUNC
225 * faking code in socket.c.
228 #define ISC_PLATFORM_RECVOVERFLOW
231 #define ISC__IPADDR(x) ((isc_uint32_t)htonl((isc_uint32_t)(x)))
233 #define ISC_IPADDR_ISMULTICAST(i) \
234 (((isc_uint32_t)(i) & ISC__IPADDR(0xf0000000)) \
235 == ISC__IPADDR(0xe0000000))
237 #define ISC_IPADDR_ISEXPERIMENTAL(i) \
238 (((isc_uint32_t)(i) & ISC__IPADDR(0xf0000000)) \
239 == ISC__IPADDR(0xf0000000))
248 isc_net_probeipv4(void);
250 * Check if the system's kernel supports IPv4.
254 * ISC_R_SUCCESS IPv4 is supported.
255 * ISC_R_NOTFOUND IPv4 is not supported.
256 * ISC_R_DISABLED IPv4 is disabled.
261 isc_net_probeipv6(void);
263 * Check if the system's kernel supports IPv6.
267 * ISC_R_SUCCESS IPv6 is supported.
268 * ISC_R_NOTFOUND IPv6 is not supported.
269 * ISC_R_DISABLED IPv6 is disabled.
274 isc_net_probe_ipv6only(void);
276 * Check if the system's kernel supports the IPV6_V6ONLY socket option.
280 * ISC_R_SUCCESS the option is supported for both TCP and UDP.
281 * ISC_R_NOTFOUND IPv6 itself or the option is not supported.
286 isc_net_probe_ipv6pktinfo(void);
288 * Check if the system's kernel supports the IPV6_(RECV)PKTINFO socket option
293 * ISC_R_SUCCESS the option is supported.
294 * ISC_R_NOTFOUND IPv6 itself or the option is not supported.
299 isc_net_disableipv4(void);
302 isc_net_disableipv6(void);
305 isc_net_enableipv4(void);
308 isc_net_enableipv6(void);
310 #ifdef ISC_PLATFORM_NEEDNTOP
312 isc_net_ntop(int af
, const void *src
, char *dst
, size_t size
);
313 #define inet_ntop isc_net_ntop
316 #ifdef ISC_PLATFORM_NEEDPTON
318 isc_net_pton(int af
, const char *src
, void *dst
);
320 #define inet_pton isc_net_pton
323 #ifdef ISC_PLATFORM_NEEDATON
325 isc_net_aton(const char *cp
, struct in_addr
*addr
);
326 #define inet_aton isc_net_aton
331 #endif /* ISC_NET_H */