]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ntp/include/isc/netaddr.h
This commit was generated by cvs2svn to compensate for changes in r174531,
[FreeBSD/FreeBSD.git] / contrib / ntp / include / isc / netaddr.h
1 /*
2  * Copyright (C) 1998-2002  Internet Software Consortium.
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
9  * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
10  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
11  * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
13  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
14  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: netaddr.h,v 1.21 2002/04/03 06:38:35 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 #include "ntp_rfc2553.h"
27
28
29
30 ISC_LANG_BEGINDECLS
31
32 struct isc_netaddr {
33         unsigned int family;
34         union {
35                 struct in_addr in;
36                 struct in6_addr in6;
37         } type;
38 };
39
40 isc_boolean_t
41 isc_netaddr_equal(const isc_netaddr_t *a, const isc_netaddr_t *b);
42
43 isc_boolean_t
44 isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b,
45                      unsigned int prefixlen);
46 /*
47  * Compare the 'prefixlen' most significant bits of the network
48  * addresses 'a' and 'b'.  Return ISC_TRUE if they are equal,
49  * ISC_FALSE if not.
50  */
51
52 isc_result_t
53 isc_netaddr_masktoprefixlen(const isc_netaddr_t *s, unsigned int *lenp);
54 /*
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.
59  *
60  * Returns:
61  *      ISC_R_SUCCESS
62  *      ISC_R_MASKNONCONTIG
63  */
64
65 isc_result_t
66 isc_netaddr_totext(const isc_netaddr_t *netaddr, isc_buffer_t *target);
67 /*
68  * Append a text representation of 'sockaddr' to the buffer 'target'.
69  * The text is NOT null terminated.  Handles IPv4 and IPv6 addresses.
70  *
71  * Returns:
72  *      ISC_R_SUCCESS
73  *      ISC_R_NOSPACE   The text or the null termination did not fit.
74  *      ISC_R_FAILURE   Unspecified failure
75  */
76
77 void
78 isc_netaddr_format(const isc_netaddr_t *na, char *array, unsigned int size);
79 /*
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.
83  */
84
85 #define ISC_NETADDR_FORMATSIZE \
86         sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX")
87 /*
88  * Minimum size of array to pass to isc_netaddr_format().
89  */
90
91 void
92 isc_netaddr_fromsockaddr(isc_netaddr_t *netaddr, const isc_sockaddr_t *source);
93
94 void
95 isc_netaddr_fromin(isc_netaddr_t *netaddr, const struct in_addr *ina);
96
97 void
98 isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6);
99
100 void
101 isc_netaddr_any(isc_netaddr_t *netaddr);
102 /*
103  * Return the IPv4 wildcard address.
104  */
105
106 void
107 isc_netaddr_any6(isc_netaddr_t *netaddr);
108 /*
109  * Return the IPv6 wildcard address.
110  */
111
112 isc_boolean_t
113 isc_netaddr_ismulticast(isc_netaddr_t *na);
114 /*
115  * Returns ISC_TRUE if the address is a multicast address.
116  */
117
118 isc_boolean_t
119 isc_netaddr_islinklocal(isc_netaddr_t *na);
120 /*
121  * Returns ISC_TRUE if the address is a link local address.
122  */
123
124 isc_boolean_t
125 isc_netaddr_issitelocal(isc_netaddr_t *na);
126 /*
127  * Returns ISC_TRUE if the address is a site local address.
128  */
129
130 void
131 isc_netaddr_fromv4mapped(isc_netaddr_t *t, const isc_netaddr_t *s);
132 /*
133  * Convert an IPv6 v4mapped address into an IPv4 address.
134  */
135
136
137 ISC_LANG_ENDDECLS
138
139 #endif /* ISC_NETADDR_H */