Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / ntp / include / isc / sockaddr.h
blob8a285317f56917a665b423c1a4f8b58c83c9b2eb
1 /* $NetBSD: sockaddr.h,v 1.2 2003/12/04 16:23:36 drochner Exp $ */
3 /*
4 * Copyright (C) 1998-2002 Internet Software Consortium.
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
11 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
12 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
13 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
15 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
16 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
17 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 /* Id: sockaddr.h,v 1.39 2002/04/03 06:38:36 marka Exp */
22 #ifndef ISC_SOCKADDR_H
23 #define ISC_SOCKADDR_H 1
25 #include <isc/lang.h>
26 #include <isc/net.h>
27 #include <isc/types.h>
29 struct isc_sockaddr {
30 union {
31 struct sockaddr sa;
32 struct sockaddr_in sin;
33 struct sockaddr_in6 sin6;
34 } type;
35 unsigned int length; /* XXXRTH beginning? */
36 ISC_LINK(struct isc_sockaddr) link;
39 typedef ISC_LIST(struct isc_sockaddr) isc_sockaddrlist_t;
41 ISC_LANG_BEGINDECLS
43 isc_boolean_t
44 isc_sockaddr_equal(const isc_sockaddr_t *a, const isc_sockaddr_t *b);
46 * Return ISC_TRUE iff the socket addresses 'a' and 'b' are equal.
49 isc_boolean_t
50 isc_sockaddr_eqaddr(const isc_sockaddr_t *a, const isc_sockaddr_t *b);
52 * Return ISC_TRUE iff the address parts of the socket addresses
53 * 'a' and 'b' are equal, ignoring the ports.
56 isc_boolean_t
57 isc_sockaddr_eqaddrprefix(const isc_sockaddr_t *a, const isc_sockaddr_t *b,
58 unsigned int prefixlen);
60 * Return ISC_TRUE iff the most significant 'prefixlen' bits of the
61 * socket addresses 'a' and 'b' are equal, ignoring the ports.
64 unsigned int
65 isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, isc_boolean_t address_only);
67 * Return a hash value for the socket address 'sockaddr'. If 'address_only'
68 * is ISC_TRUE, the hash value will not depend on the port.
70 * IPv6 addresses containing mapped IPv4 addresses generate the same hash
71 * value as the equivalent IPv4 address.
74 void
75 isc_sockaddr_any(isc_sockaddr_t *sockaddr);
77 * Return the IPv4 wildcard address.
80 void
81 isc_sockaddr_any6(isc_sockaddr_t *sockaddr);
83 * Return the IPv6 wildcard address.
86 void
87 isc_sockaddr_anyofpf(isc_sockaddr_t *sockaddr, int family);
89 * Set '*sockaddr' to the wildcard address of protocol family
90 * 'family'.
92 * Requires:
93 * 'family' is AF_INET or AF_INET6.
96 void
97 isc_sockaddr_fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
98 in_port_t port);
100 * Construct an isc_sockaddr_t from an IPv4 address and port.
103 void
104 isc_sockaddr_fromin6(isc_sockaddr_t *sockaddr, const struct in6_addr *ina6,
105 in_port_t port);
107 * Construct an isc_sockaddr_t from an IPv6 address and port.
110 void
111 isc_sockaddr_v6fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
112 in_port_t port);
114 * Construct an IPv6 isc_sockaddr_t representing a mapped IPv4 address.
117 void
118 isc_sockaddr_fromnetaddr(isc_sockaddr_t *sockaddr, const isc_netaddr_t *na,
119 in_port_t port);
121 * Construct an isc_sockaddr_t from an isc_netaddr_t and port.
125 isc_sockaddr_pf(const isc_sockaddr_t *sockaddr);
127 * Get the protocol family of 'sockaddr'.
129 * Requires:
131 * 'sockaddr' is a valid sockaddr with an address family of AF_INET
132 * or AF_INET6.
134 * Returns:
136 * The protocol family of 'sockaddr', e.g. PF_INET or PF_INET6.
139 void
140 isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port);
142 * Set the port of 'sockaddr' to 'port'.
145 in_port_t
146 isc_sockaddr_getport(isc_sockaddr_t *sockaddr);
148 * Get the port stored in 'sockaddr'.
151 isc_result_t
152 isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target);
154 * Append a text representation of 'sockaddr' to the buffer 'target'.
155 * The text will include both the IP address (v4 or v6) and the port.
156 * The text is null terminated, but the terminating null is not
157 * part of the buffer's used region.
159 * Returns:
160 * ISC_R_SUCCESS
161 * ISC_R_NOSPACE The text or the null termination did not fit.
164 void
165 isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size);
167 * Format a human-readable representation of the socket address '*sa'
168 * into the character array 'array', which is of size 'size'.
169 * The resulting string is guaranteed to be null-terminated.
172 isc_boolean_t
173 isc_sockaddr_ismulticast(isc_sockaddr_t *sa);
175 * Returns ISC_TRUE if the address is a multicast address.
178 isc_boolean_t
179 isc_sockaddr_isexperimental(isc_sockaddr_t *sa);
181 * Returns ISC_TRUE if the address is a experimental (CLASS E) address.
184 isc_boolean_t
185 isc_sockaddr_islinklocal(isc_sockaddr_t *sa);
187 * Returns ISC_TRUE if the address is a link local addresss.
190 isc_boolean_t
191 isc_sockaddr_issitelocal(isc_sockaddr_t *sa);
193 * Returns ISC_TRUE if the address is a sitelocal address.
196 #define ISC_SOCKADDR_FORMATSIZE \
197 sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX#YYYYY")
199 * Minimum size of array to pass to isc_sockaddr_format().
202 ISC_LANG_ENDDECLS
204 #endif /* ISC_SOCKADDR_H */