Merge from vendor branch BINUTILS:
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / isc / include / isc / sockaddr.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: sockaddr.h,v 1.35.2.2 2004/03/09 06:12:01 marka Exp $ */
19
20 #ifndef ISC_SOCKADDR_H
21 #define ISC_SOCKADDR_H 1
22
23 #include <isc/lang.h>
24 #include <isc/net.h>
25 #include <isc/types.h>
26
27 struct isc_sockaddr {
28         union {
29                 struct sockaddr         sa;
30                 struct sockaddr_in      sin;
31                 struct sockaddr_in6     sin6;
32         }                               type;
33         unsigned int                    length;         /* XXXRTH beginning? */
34         ISC_LINK(struct isc_sockaddr)   link;
35 };
36
37 typedef ISC_LIST(struct isc_sockaddr)   isc_sockaddrlist_t;
38
39 ISC_LANG_BEGINDECLS
40
41 isc_boolean_t
42 isc_sockaddr_equal(const isc_sockaddr_t *a, const isc_sockaddr_t *b);
43 /*
44  * Return ISC_TRUE iff the socket addresses 'a' and 'b' are equal.
45  */
46
47 isc_boolean_t
48 isc_sockaddr_eqaddr(const isc_sockaddr_t *a, const isc_sockaddr_t *b);
49 /*
50  * Return ISC_TRUE iff the address parts of the socket addresses
51  * 'a' and 'b' are equal, ignoring the ports.
52  */
53
54 isc_boolean_t
55 isc_sockaddr_eqaddrprefix(const isc_sockaddr_t *a, const isc_sockaddr_t *b,
56                           unsigned int prefixlen);
57 /*
58  * Return ISC_TRUE iff the most significant 'prefixlen' bits of the
59  * socket addresses 'a' and 'b' are equal, ignoring the ports.
60  */
61
62 unsigned int
63 isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, isc_boolean_t address_only);
64 /*
65  * Return a hash value for the socket address 'sockaddr'.  If 'address_only'
66  * is ISC_TRUE, the hash value will not depend on the port.
67  */
68
69 void
70 isc_sockaddr_any(isc_sockaddr_t *sockaddr);
71 /*
72  * Return the IPv4 wildcard address.
73  */
74
75 void
76 isc_sockaddr_any6(isc_sockaddr_t *sockaddr);
77 /*
78  * Return the IPv6 wildcard address.
79  */
80
81 void
82 isc_sockaddr_anyofpf(isc_sockaddr_t *sockaddr, int family);
83 /*
84  * Set '*sockaddr' to the wildcard address of protocol family
85  * 'family'.
86  *
87  * Requires:
88  *      'family' is AF_INET or AF_INET6.
89  */
90
91 void
92 isc_sockaddr_fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
93                     in_port_t port);
94 /*
95  * Construct an isc_sockaddr_t from an IPv4 address and port.
96  */
97
98 void
99 isc_sockaddr_fromin6(isc_sockaddr_t *sockaddr, const struct in6_addr *ina6,
100                      in_port_t port);
101 /*
102  * Construct an isc_sockaddr_t from an IPv6 address and port.
103  */
104
105 void
106 isc_sockaddr_v6fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
107                       in_port_t port);
108 /*
109  * Construct an IPv6 isc_sockaddr_t representing a mapped IPv4 address.
110  */
111
112 void
113 isc_sockaddr_fromnetaddr(isc_sockaddr_t *sockaddr, const isc_netaddr_t *na,
114                          in_port_t port);
115 /*
116  * Construct an isc_sockaddr_t from an isc_netaddr_t and port.
117  */
118
119 int
120 isc_sockaddr_pf(const isc_sockaddr_t *sockaddr);
121 /*
122  * Get the protocol family of 'sockaddr'.
123  *
124  * Requires:
125  *
126  *      'sockaddr' is a valid sockaddr with an address family of AF_INET
127  *      or AF_INET6.
128  *
129  * Returns:
130  *
131  *      The protocol family of 'sockaddr', e.g. PF_INET or PF_INET6.
132  */
133
134 void
135 isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port);
136 /*
137  * Set the port of 'sockaddr' to 'port'.
138  */
139
140 in_port_t
141 isc_sockaddr_getport(isc_sockaddr_t *sockaddr);
142 /*
143  * Get the port stored in 'sockaddr'.
144  */
145
146 isc_result_t
147 isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target);
148 /*
149  * Append a text representation of 'sockaddr' to the buffer 'target'.
150  * The text will include both the IP address (v4 or v6) and the port.
151  * The text is null terminated, but the terminating null is not
152  * part of the buffer's used region.
153  *
154  * Returns:
155  *      ISC_R_SUCCESS
156  *      ISC_R_NOSPACE   The text or the null termination did not fit.
157  */
158
159 void
160 isc_sockaddr_format(isc_sockaddr_t *sa, char *array, unsigned int size);
161 /*
162  * Format a human-readable representation of the socket address '*sa'
163  * into the character array 'array', which is of size 'size'.
164  * The resulting string is guaranteed to be null-terminated.
165  */
166
167 isc_boolean_t
168 isc_sockaddr_ismulticast(isc_sockaddr_t *sa);
169 /*
170  * Returns ISC_TRUE if the address is a multicast address
171  */
172
173 isc_boolean_t
174 isc_sockaddr_isexperimental(isc_sockaddr_t *sa);
175 /*
176  * Returns ISC_TRUE if the address is a experimental (CLASS E) address.
177  */
178
179 #define ISC_SOCKADDR_FORMATSIZE \
180         sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX#YYYYY")
181 /*
182  * Minimum size of array to pass to isc_sockaddr_format().
183  */
184
185 ISC_LANG_ENDDECLS
186
187 #endif /* ISC_SOCKADDR_H */