Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / ntp / include / isc / net.h
blob96b9963c1faba3412cfa7fa5b01767b2dd020c24
1 /* $NetBSD: net.h,v 1.2 2003/12/04 16:23:36 drochner Exp $ */
3 /*
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 */
22 #ifndef ISC_NET_H
23 #define ISC_NET_H 1
25 /*****
26 ***** Module Info
27 *****/
30 * Basic Networking Types
32 * This module is responsible for defining the following basic networking
33 * types:
35 * struct in_addr
36 * struct in6_addr
37 * struct in6_pktinfo
38 * struct sockaddr
39 * struct sockaddr_in
40 * struct sockaddr_in6
41 * in_port_t
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
53 * addresses.
55 * MP:
56 * No impact.
58 * Reliability:
59 * No anticipated impact.
61 * Resources:
62 * N/A.
64 * Security:
65 * No anticipated impact.
67 * Standards:
68 * BSD Socket API
69 * RFC 2553
72 /***
73 *** Imports.
74 ***/
75 #include <isc/platform.h>
77 #include <sys/types.h>
78 #include <sys/socket.h> /* Contractual promise. */
80 #include <net/if.h>
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. */
86 #endif
87 #ifdef ISC_PLATFORM_NEEDNETINET6IN6H
88 #include <netinet6/in6.h> /* Required on BSD/OS for in6_pktinfo. */
89 #endif
91 #ifndef ISC_PLATFORM_HAVEIPV6
92 #include <isc/ipv6.h> /* Contractual promise. */
93 #endif
95 #include <isc/lang.h>
96 #include <isc/types.h>
98 #ifdef ISC_PLATFORM_HAVEINADDR6
99 #define in6_addr in_addr6 /* Required for pre RFC2133 implementations. */
100 #endif
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
111 #ifdef s6_addr
112 #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
113 #else
114 #define IN6ADDR_ANY_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } }
115 #endif
116 #endif
118 #ifndef IN6ADDR_LOOPBACK_INIT
119 #ifdef s6_addr
120 #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
121 #else
122 #define IN6ADDR_LOOPBACK_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } }
123 #endif
124 #endif
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)
130 #endif
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)))
138 #endif
140 #ifndef IN6_IS_ADDR_MULTICAST
141 #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
142 #endif
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))
147 #endif
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))
152 #endif
155 #ifndef IN6_IS_ADDR_LOOPBACK
156 #define IN6_IS_ADDR_LOOPBACK(x) \
157 (memcmp((x)->s6_addr, in6addr_loopback.s6_addr, 16) == 0)
158 #endif
159 #endif
161 #ifndef AF_INET6
162 #define AF_INET6 99
163 #endif
165 #ifndef PF_INET6
166 #define PF_INET6 AF_INET6
167 #endif
169 #ifndef INADDR_LOOPBACK
170 #define INADDR_LOOPBACK 0x7f000001UL
171 #endif
173 #if 0
174 #ifndef ISC_PLATFORM_HAVEIN6PKTINFO
175 struct in6_pktinfo {
176 struct in6_addr ipi6_addr; /* src/dst IPv6 address */
177 unsigned int ipi6_ifindex; /* send/recv interface index */
179 #endif
180 #endif
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
188 #endif
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
193 #endif
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;
220 #endif
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.
227 #ifndef MSG_TRUNC
228 #define ISC_PLATFORM_RECVOVERFLOW
229 #endif
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))
241 /***
242 *** Functions.
243 ***/
245 ISC_LANG_BEGINDECLS
247 isc_result_t
248 isc_net_probeipv4(void);
250 * Check if the system's kernel supports IPv4.
252 * Returns:
254 * ISC_R_SUCCESS IPv4 is supported.
255 * ISC_R_NOTFOUND IPv4 is not supported.
256 * ISC_R_DISABLED IPv4 is disabled.
257 * ISC_R_UNEXPECTED
260 isc_result_t
261 isc_net_probeipv6(void);
263 * Check if the system's kernel supports IPv6.
265 * Returns:
267 * ISC_R_SUCCESS IPv6 is supported.
268 * ISC_R_NOTFOUND IPv6 is not supported.
269 * ISC_R_DISABLED IPv6 is disabled.
270 * ISC_R_UNEXPECTED
273 isc_result_t
274 isc_net_probe_ipv6only(void);
276 * Check if the system's kernel supports the IPV6_V6ONLY socket option.
278 * Returns:
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.
282 * ISC_R_UNEXPECTED
285 isc_result_t
286 isc_net_probe_ipv6pktinfo(void);
288 * Check if the system's kernel supports the IPV6_(RECV)PKTINFO socket option
289 * for UDP sockets.
291 * Returns:
293 * ISC_R_SUCCESS the option is supported.
294 * ISC_R_NOTFOUND IPv6 itself or the option is not supported.
295 * ISC_R_UNEXPECTED
298 void
299 isc_net_disableipv4(void);
301 void
302 isc_net_disableipv6(void);
304 void
305 isc_net_enableipv4(void);
307 void
308 isc_net_enableipv6(void);
310 #ifdef ISC_PLATFORM_NEEDNTOP
311 const char *
312 isc_net_ntop(int af, const void *src, char *dst, size_t size);
313 #define inet_ntop isc_net_ntop
314 #endif
316 #ifdef ISC_PLATFORM_NEEDPTON
318 isc_net_pton(int af, const char *src, void *dst);
319 #undef inet_pton
320 #define inet_pton isc_net_pton
321 #endif
323 #ifdef ISC_PLATFORM_NEEDATON
325 isc_net_aton(const char *cp, struct in_addr *addr);
326 #define inet_aton isc_net_aton
327 #endif
329 ISC_LANG_ENDDECLS
331 #endif /* ISC_NET_H */