1 /* $NetBSD: netaddr.h,v 1.3 2003/12/04 16:52:28 drochner Exp $ */
4 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2002 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: netaddr.h,v 1.18.12.7 2004/03/08 09:04:52 marka Exp */
23 #define ISC_NETADDR_H 1
27 #include <isc/types.h>
41 isc_netaddr_equal(const isc_netaddr_t
*a
, const isc_netaddr_t
*b
);
44 isc_netaddr_eqprefix(const isc_netaddr_t
*a
, const isc_netaddr_t
*b
,
45 unsigned int prefixlen
);
47 * Compare the 'prefixlen' most significant bits of the network
48 * addresses 'a' and 'b'. Return ISC_TRUE if they are equal,
53 isc_netaddr_masktoprefixlen(const isc_netaddr_t
*s
, unsigned int *lenp
);
55 * Convert a netmask in 's' into a prefix length in '*lenp'.
56 * The mask should consist of zero or more '1' bits in the most
57 * most significant part of the address, followed by '0' bits.
58 * If this is not the case, ISC_R_MASKNONCONTIG is returned.
66 isc_netaddr_totext(const isc_netaddr_t
*netaddr
, isc_buffer_t
*target
);
68 * Append a text representation of 'sockaddr' to the buffer 'target'.
69 * The text is NOT null terminated. Handles IPv4 and IPv6 addresses.
73 * ISC_R_NOSPACE The text or the null termination did not fit.
74 * ISC_R_FAILURE Unspecified failure
78 isc_netaddr_format(const isc_netaddr_t
*na
, char *array
, unsigned int size
);
80 * Format a human-readable representation of the network address '*na'
81 * into the character array 'array', which is of size 'size'.
82 * The resulting string is guaranteed to be null-terminated.
85 #define ISC_NETADDR_FORMATSIZE \
86 sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX")
88 * Minimum size of array to pass to isc_netaddr_format().
92 isc_netaddr_fromsockaddr(isc_netaddr_t
*netaddr
, const isc_sockaddr_t
*source
);
95 isc_netaddr_fromin(isc_netaddr_t
*netaddr
, const struct in_addr
*ina
);
98 isc_netaddr_fromin6(isc_netaddr_t
*netaddr
, const struct in6_addr
*ina6
);
101 isc_netaddr_setzone(isc_netaddr_t
*netaddr
, isc_uint32_t zone
);
104 isc_netaddr_getzone(const isc_netaddr_t
*netaddr
);
107 isc_netaddr_any(isc_netaddr_t
*netaddr
);
109 * Return the IPv4 wildcard address.
113 isc_netaddr_any6(isc_netaddr_t
*netaddr
);
115 * Return the IPv6 wildcard address.
119 isc_netaddr_ismulticast(isc_netaddr_t
*na
);
121 * Returns ISC_TRUE if the address is a multicast address.
125 isc_netaddr_isexperimental(isc_netaddr_t
*na
);
127 * Returns ISC_TRUE if the address is a experimental (CLASS E) address.
131 isc_netaddr_islinklocal(isc_netaddr_t
*na
);
133 * Returns ISC_TRUE if the address is a link local address.
137 isc_netaddr_issitelocal(isc_netaddr_t
*na
);
139 * Returns ISC_TRUE if the address is a site local address.
143 isc_netaddr_fromv4mapped(isc_netaddr_t
*t
, const isc_netaddr_t
*s
);
145 * Convert an IPv6 v4mapped address into an IPv4 address.
151 #endif /* ISC_NETADDR_H */