2 * Copyright (C) 2004, 2005, 2007, 2008, 2012 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
26 * Also define LWRES_IPV6_H to keep it from being included if liblwres is
27 * being used, or redefinition errors will occur.
29 #define LWRES_IPV6_H 1
38 * Basic Networking Types
40 * This module is responsible for defining the following basic networking
51 * It ensures that the AF_ and PF_ macros are defined.
53 * It declares ntoh[sl]() and hton[sl]().
55 * It declares inet_aton(), inet_ntop(), and inet_pton().
57 * It ensures that INADDR_ANY, IN6ADDR_ANY_INIT, in6addr_any, and
58 * in6addr_loopback are available.
60 * It ensures that IN_MULTICAST() is available to check for multicast
67 * No anticipated impact.
73 * No anticipated impact.
83 #include <isc/platform.h>
86 * Because of some sort of problem in the MS header files, this cannot
87 * be simple "#include <winsock2.h>", because winsock2.h tries to include
88 * windows.h, which then generates an error out of mswsock.h. _You_
92 #define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */
97 #include <sys/types.h>
100 #include <isc/types.h>
102 #include <ws2tcpip.h>
103 #include <isc/ipv6.h>
106 * This is here because named client, interfacemgr.c, etc. use the name as
111 #ifndef INADDR_LOOPBACK
112 #define INADDR_LOOPBACK 0x7f000001UL
115 #ifndef ISC_PLATFORM_HAVEIN6PKTINFO
117 struct in6_addr ipi6_addr; /* src/dst IPv6 address */
118 unsigned int ipi6_ifindex; /* send/recv interface index */
123 #define in6addr_any isc_net_in6addrany
124 #define in6addr_loopback isc_net_in6addrloop
128 * Ensure type in_port_t is defined.
130 #ifdef ISC_PLATFORM_NEEDPORTT
131 typedef isc_uint16_t in_port_t;
135 * If this system does not have MSG_TRUNC (as returned from recvmsg())
136 * ISC_PLATFORM_RECVOVERFLOW will be defined. This will enable the MSG_TRUNC
137 * faking code in socket.c.
140 #define ISC_PLATFORM_RECVOVERFLOW
143 #define ISC__IPADDR(x) ((isc_uint32_t)htonl((isc_uint32_t)(x)))
145 #define ISC_IPADDR_ISMULTICAST(i) \
146 (((isc_uint32_t)(i) & ISC__IPADDR(0xf0000000)) \
147 == ISC__IPADDR(0xe0000000))
149 #define ISC_IPADDR_ISEXPERIMENTAL(i) \
150 (((isc_uint32_t)(i) & ISC__IPADDR(0xf0000000)) \
151 == ISC__IPADDR(0xf0000000))
154 * Fix the FD_SET and FD_CLR Macros to properly cast
157 #define FD_CLR(fd, set) do { \
159 for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count; __i++) { \
160 if (((fd_set FAR *)(set))->fd_array[__i] == (SOCKET) fd) { \
161 while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
162 ((fd_set FAR *)(set))->fd_array[__i] = \
163 ((fd_set FAR *)(set))->fd_array[__i+1]; \
166 ((fd_set FAR *)(set))->fd_count--; \
173 #define FD_SET(fd, set) do { \
175 for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count; __i++) { \
176 if (((fd_set FAR *)(set))->fd_array[__i] == (SOCKET)(fd)) { \
180 if (__i == ((fd_set FAR *)(set))->fd_count) { \
181 if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) { \
182 ((fd_set FAR *)(set))->fd_array[__i] = (SOCKET)(fd); \
183 ((fd_set FAR *)(set))->fd_count++; \
189 * Windows Sockets errors redefined as regular Berkeley error constants.
190 * These are usually commented out in Windows NT to avoid conflicts with errno.h.
191 * Use the WSA constants instead.
192 * Starting with VC9 (VC++ 2010) many of these are defined incompatibly
193 * by errno.h -- #undef the conflicting values, which are not relevant to
198 #define EWOULDBLOCK WSAEWOULDBLOCK
200 #define EINPROGRESS WSAEINPROGRESS
202 #define EALREADY WSAEALREADY
204 #define ENOTSOCK WSAENOTSOCK
206 #define EDESTADDRREQ WSAEDESTADDRREQ
208 #define EMSGSIZE WSAEMSGSIZE
210 #define EPROTOTYPE WSAEPROTOTYPE
212 #define ENOPROTOOPT WSAENOPROTOOPT
213 #undef EPROTONOSUPPORT
214 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
215 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
217 #define EOPNOTSUPP WSAEOPNOTSUPP
218 #define EPFNOSUPPORT WSAEPFNOSUPPORT
220 #define EAFNOSUPPORT WSAEAFNOSUPPORT
222 #define EADDRINUSE WSAEADDRINUSE
224 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
226 #define ENETDOWN WSAENETDOWN
228 #define ENETUNREACH WSAENETUNREACH
230 #define ENETRESET WSAENETRESET
232 #define ECONNABORTED WSAECONNABORTED
234 #define ECONNRESET WSAECONNRESET
236 #define ENOBUFS WSAENOBUFS
238 #define EISCONN WSAEISCONN
240 #define ENOTCONN WSAENOTCONN
241 #define ESHUTDOWN WSAESHUTDOWN
242 #define ETOOMANYREFS WSAETOOMANYREFS
244 #define ETIMEDOUT WSAETIMEDOUT
246 #define ECONNREFUSED WSAECONNREFUSED
248 #define ELOOP WSAELOOP
249 #define EHOSTDOWN WSAEHOSTDOWN
251 #define EHOSTUNREACH WSAEHOSTUNREACH
252 #define EPROCLIM WSAEPROCLIM
253 #define EUSERS WSAEUSERS
254 #define EDQUOT WSAEDQUOT
255 #define ESTALE WSAESTALE
256 #define EREMOTE WSAEREMOTE
266 isc_net_probeipv4(void);
268 * Check if the system's kernel supports IPv4.
272 * ISC_R_SUCCESS IPv4 is supported.
273 * ISC_R_NOTFOUND IPv4 is not supported.
274 * ISC_R_DISABLED IPv4 is disabled.
279 isc_net_probeipv6(void);
281 * Check if the system's kernel supports IPv6.
285 * ISC_R_SUCCESS IPv6 is supported.
286 * ISC_R_NOTFOUND IPv6 is not supported.
287 * ISC_R_DISABLED IPv6 is disabled.
292 isc_net_probeunix(void);
294 * Check if UNIX domain sockets are supported.
303 isc_net_probe_ipv6only(void);
305 * Check if the system's kernel supports the IPV6_V6ONLY socket option.
309 * ISC_R_SUCCESS the option is supported for both TCP and UDP.
310 * ISC_R_NOTFOUND IPv6 itself or the option is not supported.
315 isc_net_probe_ipv6pktinfo(void);
317 * Check if the system's kernel supports the IPV6_(RECV)PKTINFO socket option
322 * ISC_R_SUCCESS the option is supported.
323 * ISC_R_NOTFOUND IPv6 itself or the option is not supported.
328 isc_net_disableipv4(void);
331 isc_net_disableipv6(void);
334 isc_net_enableipv4(void);
337 isc_net_enableipv6(void);
340 isc_net_getudpportrange(int af, in_port_t *low, in_port_t *high);
342 * Returns system's default range of ephemeral UDP ports, if defined.
343 * If the range is not available or unknown, ISC_NET_PORTRANGELOW and
344 * ISC_NET_PORTRANGEHIGH will be returned.
348 *\li 'low' and 'high' must be non NULL.
352 *\li *low and *high will be the ports specifying the low and high ends of
356 #ifdef ISC_PLATFORM_NEEDNTOP
358 isc_net_ntop(int af, const void *src, char *dst, size_t size);
359 #define inet_ntop isc_net_ntop
362 #ifdef ISC_PLATFORM_NEEDPTON
364 isc_net_pton(int af, const char *src, void *dst);
365 #define inet_pton isc_net_pton
369 isc_net_aton(const char *cp, struct in_addr *addr);
370 #define inet_aton isc_net_aton
374 #endif /* ISC_NET_H */