netaddr.h 2.98 KB
Newer Older
1
/*
Bob Halley's avatar
Bob Halley committed
2
 * Copyright (C) 1998, 1999, 2000  Internet Software Consortium.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 * 
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

#ifndef ISC_NETADDR_H
#define ISC_NETADDR_H 1

#include <isc/lang.h>
22
#include <isc/net.h>
23
#include <isc/types.h>
24
25
26

ISC_LANG_BEGINDECLS

27
struct isc_netaddr {
28
	unsigned int family;
29
30
31
32
	union {
    		struct in_addr in;
		struct in6_addr in6;
	} type;
33
34
};

Andreas Gustafsson's avatar
Andreas Gustafsson committed
35
36
37
isc_boolean_t
isc_netaddr_equal(const isc_netaddr_t *a, const isc_netaddr_t *b);

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
isc_boolean_t
isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b,
		     unsigned int prefixlen);
/*
 * Compare the 'prefixlen' most significant bits of the network
 * addresses 'a' and 'b'.  Return ISC_TRUE if they are equal,
 * ISC_FALSE if not.
 */

isc_result_t
isc_netaddr_masktoprefixlen(const isc_netaddr_t *s, unsigned int *lenp);
/*
 * Convert a netmask in 's' into a prefix length in '*lenp'.
 * The mask should consist of zero or more '1' bits in the most
 * most significant part of the address, followed by '0' bits.
 * If this is not the case, ISC_R_MASKNONCONTIG is returned.
 *
 * Returns:
 *	ISC_R_SUCCESS
 *	ISC_R_MASKNONCONTIG
 */

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
isc_result_t
isc_netaddr_totext(const isc_netaddr_t *netaddr, isc_buffer_t *target);
/*
 * Append a text representation of 'sockaddr' to the buffer 'target'.
 * The text is NOT null terminated.  Handles IPv4 and IPv6 addresses.  
 *
 * Returns:
 *	ISC_R_SUCCESS
 *	ISC_R_NOSPACE	The text or the null termination did not fit.
 *	ISC_R_FAILURE	Unspecified failure
 */

void
isc_netaddr_format(isc_netaddr_t *na, char *array, unsigned int size);
/*
 * Format a human-readable representation of the network address '*na'
 * into the character array 'array', which is of size 'size'.
 * The resulting string is guaranteed to be null-terminated.
 */

80
81
82
83
84
85
#define ISC_NETADDR_FORMATSIZE \
	sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX")
/*
 * Minimum size of array to pass to isc_netaddr_format().
 */

86
87
88
89
90
91
92
93
void
isc_netaddr_fromsockaddr(isc_netaddr_t *netaddr, const isc_sockaddr_t *source);

void
isc_netaddr_fromin(isc_netaddr_t *netaddr, const struct in_addr *ina);

void
isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6);
94

95
96
97
98
99
100
isc_boolean_t
isc_netaddr_ismulticast(isc_netaddr_t *na);
/*
 * Returns ISC_TRUE if the address is a multicast address
 */

101
102
103
ISC_LANG_ENDDECLS

#endif /* ISC_NETADDR_H */