2 * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998-2002 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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.
18 /* $Id: netaddr.h,v 1.25.18.5 2005/07/28 04:58:47 marka Exp $ */
21 #define ISC_NETADDR_H 1
27 #include <isc/types.h>
29 #ifdef ISC_PLATFORM_HAVESYSUNH
30 #include <sys/types.h>
41 #ifdef ISC_PLATFORM_HAVESYSUNH
42 char un[sizeof(((struct sockaddr_un *)0)->sun_path)];
49 isc_netaddr_equal(const isc_netaddr_t *a, const isc_netaddr_t *b);
52 isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b,
53 unsigned int prefixlen);
55 * Compare the 'prefixlen' most significant bits of the network
56 * addresses 'a' and 'b'. Return #ISC_TRUE if they are equal,
61 isc_netaddr_masktoprefixlen(const isc_netaddr_t *s, unsigned int *lenp);
63 * Convert a netmask in 's' into a prefix length in '*lenp'.
64 * The mask should consist of zero or more '1' bits in the most
65 * most significant part of the address, followed by '0' bits.
66 * If this is not the case, #ISC_R_MASKNONCONTIG is returned.
70 *\li #ISC_R_MASKNONCONTIG
74 isc_netaddr_totext(const isc_netaddr_t *netaddr, isc_buffer_t *target);
76 * Append a text representation of 'sockaddr' to the buffer 'target'.
77 * The text is NOT null terminated. Handles IPv4 and IPv6 addresses.
81 *\li #ISC_R_NOSPACE The text or the null termination did not fit.
82 *\li #ISC_R_FAILURE Unspecified failure
86 isc_netaddr_format(const isc_netaddr_t *na, char *array, unsigned int size);
88 * Format a human-readable representation of the network address '*na'
89 * into the character array 'array', which is of size 'size'.
90 * The resulting string is guaranteed to be null-terminated.
93 #define ISC_NETADDR_FORMATSIZE \
94 sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX%SSSSSSSSSS")
96 * Minimum size of array to pass to isc_netaddr_format().
100 isc_netaddr_fromsockaddr(isc_netaddr_t *netaddr, const isc_sockaddr_t *source);
103 isc_netaddr_fromin(isc_netaddr_t *netaddr, const struct in_addr *ina);
106 isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6);
109 isc_netaddr_frompath(isc_netaddr_t *netaddr, const char *path);
112 isc_netaddr_setzone(isc_netaddr_t *netaddr, isc_uint32_t zone);
115 isc_netaddr_getzone(const isc_netaddr_t *netaddr);
118 isc_netaddr_any(isc_netaddr_t *netaddr);
120 * Return the IPv4 wildcard address.
124 isc_netaddr_any6(isc_netaddr_t *netaddr);
126 * Return the IPv6 wildcard address.
130 isc_netaddr_ismulticast(isc_netaddr_t *na);
132 * Returns ISC_TRUE if the address is a multicast address.
136 isc_netaddr_isexperimental(isc_netaddr_t *na);
138 * Returns ISC_TRUE if the address is a experimental (CLASS E) address.
142 isc_netaddr_islinklocal(isc_netaddr_t *na);
144 * Returns #ISC_TRUE if the address is a link local address.
148 isc_netaddr_issitelocal(isc_netaddr_t *na);
150 * Returns #ISC_TRUE if the address is a site local address.
154 isc_netaddr_fromv4mapped(isc_netaddr_t *t, const isc_netaddr_t *s);
156 * Convert an IPv6 v4mapped address into an IPv4 address.
160 isc_netaddr_prefixok(const isc_netaddr_t *na, unsigned int prefixlen);
162 * Test whether the netaddr 'na' and 'prefixlen' are consistant.
163 * e.g. prefixlen within range.
164 * na does not have bits set which are not covered by the prefixlen.
168 * ISC_R_RANGE prefixlen out of range
169 * ISC_R_NOTIMPLENTED unsupported family
170 * ISC_R_FAILURE extra bits.
175 #endif /* ISC_NETADDR_H */