Merge from vendor branch GROFF:
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / isc / include / isc / netaddr.h
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1998-2001  Internet Software Consortium.
4  *
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.
8  *
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.
16  */
17
18 /* $Id: netaddr.h,v 1.18.2.2 2004/03/09 06:11:59 marka Exp $ */
19
20 #ifndef ISC_NETADDR_H
21 #define ISC_NETADDR_H 1
22
23 #include <isc/lang.h>
24 #include <isc/net.h>
25 #include <isc/types.h>
26
27 ISC_LANG_BEGINDECLS
28
29 struct isc_netaddr {
30         unsigned int family;
31         union {
32                 struct in_addr in;
33                 struct in6_addr in6;
34         } type;
35 };
36
37 isc_boolean_t
38 isc_netaddr_equal(const isc_netaddr_t *a, const isc_netaddr_t *b);
39
40 isc_boolean_t
41 isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b,
42                      unsigned int prefixlen);
43 /*
44  * Compare the 'prefixlen' most significant bits of the network
45  * addresses 'a' and 'b'.  Return ISC_TRUE if they are equal,
46  * ISC_FALSE if not.
47  */
48
49 isc_result_t
50 isc_netaddr_masktoprefixlen(const isc_netaddr_t *s, unsigned int *lenp);
51 /*
52  * Convert a netmask in 's' into a prefix length in '*lenp'.
53  * The mask should consist of zero or more '1' bits in the most
54  * most significant part of the address, followed by '0' bits.
55  * If this is not the case, ISC_R_MASKNONCONTIG is returned.
56  *
57  * Returns:
58  *      ISC_R_SUCCESS
59  *      ISC_R_MASKNONCONTIG
60  */
61
62 isc_result_t
63 isc_netaddr_totext(const isc_netaddr_t *netaddr, isc_buffer_t *target);
64 /*
65  * Append a text representation of 'sockaddr' to the buffer 'target'.
66  * The text is NOT null terminated.  Handles IPv4 and IPv6 addresses.
67  *
68  * Returns:
69  *      ISC_R_SUCCESS
70  *      ISC_R_NOSPACE   The text or the null termination did not fit.
71  *      ISC_R_FAILURE   Unspecified failure
72  */
73
74 void
75 isc_netaddr_format(isc_netaddr_t *na, char *array, unsigned int size);
76 /*
77  * Format a human-readable representation of the network address '*na'
78  * into the character array 'array', which is of size 'size'.
79  * The resulting string is guaranteed to be null-terminated.
80  */
81
82 #define ISC_NETADDR_FORMATSIZE \
83         sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX")
84 /*
85  * Minimum size of array to pass to isc_netaddr_format().
86  */
87
88 void
89 isc_netaddr_fromsockaddr(isc_netaddr_t *netaddr, const isc_sockaddr_t *source);
90
91 void
92 isc_netaddr_fromin(isc_netaddr_t *netaddr, const struct in_addr *ina);
93
94 void
95 isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6);
96
97 void
98 isc_netaddr_any(isc_netaddr_t *netaddr);
99 /*
100  * Return the IPv4 wildcard address.
101  */
102
103 void
104 isc_netaddr_any6(isc_netaddr_t *netaddr);
105 /*
106  * Return the IPv6 wildcard address.
107  */
108
109 isc_boolean_t
110 isc_netaddr_ismulticast(isc_netaddr_t *na);
111 /*
112  * Returns ISC_TRUE if the address is a multicast address
113  */
114
115 isc_boolean_t
116 isc_netaddr_isexperimental(isc_netaddr_t *na);
117 /*
118  * Returns ISC_TRUE if the address is a experimental (CLASS E) address.
119  */
120
121 void
122 isc_netaddr_fromv4mapped(isc_netaddr_t *t, const isc_netaddr_t *s);
123 /*
124  * Convert an IPv6 v4mapped address into an IPv4 address.
125  */
126
127
128 ISC_LANG_ENDDECLS
129
130 #endif /* ISC_NETADDR_H */