PageRenderTime 19ms CodeModel.GetById 6ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/contrib/ntp/include/isc/sockaddr.h

https://bitbucket.org/freebsd/freebsd-head/
C++ Header | 202 lines | 65 code | 29 blank | 108 comment | 0 complexity | 90d66bc20da58a1c69ee9f54c1b793a1 MD5 | raw file
  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: sockaddr.h,v 1.39 2002/04/03 06:38:36 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
 27struct 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
 37typedef ISC_LIST(struct isc_sockaddr)	isc_sockaddrlist_t;
 38
 39ISC_LANG_BEGINDECLS
 40
 41isc_boolean_t
 42isc_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
 47isc_boolean_t
 48isc_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
 54isc_boolean_t
 55isc_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
 62unsigned int
 63isc_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 * IPv6 addresses containing mapped IPv4 addresses generate the same hash
 69 * value as the equivalent IPv4 address.
 70 */
 71
 72void
 73isc_sockaddr_any(isc_sockaddr_t *sockaddr);
 74/*
 75 * Return the IPv4 wildcard address.
 76 */
 77
 78void
 79isc_sockaddr_any6(isc_sockaddr_t *sockaddr);
 80/*
 81 * Return the IPv6 wildcard address.
 82 */
 83
 84void
 85isc_sockaddr_anyofpf(isc_sockaddr_t *sockaddr, int family);
 86/*
 87 * Set '*sockaddr' to the wildcard address of protocol family
 88 * 'family'.
 89 *
 90 * Requires:
 91 *	'family' is AF_INET or AF_INET6.
 92 */
 93
 94void
 95isc_sockaddr_fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
 96		    in_port_t port);
 97/*
 98 * Construct an isc_sockaddr_t from an IPv4 address and port.
 99 */
100
101void
102isc_sockaddr_fromin6(isc_sockaddr_t *sockaddr, const struct in6_addr *ina6,
103		     in_port_t port);
104/*
105 * Construct an isc_sockaddr_t from an IPv6 address and port.
106 */
107
108void
109isc_sockaddr_v6fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
110		      in_port_t port);
111/*
112 * Construct an IPv6 isc_sockaddr_t representing a mapped IPv4 address.
113 */
114
115void
116isc_sockaddr_fromnetaddr(isc_sockaddr_t *sockaddr, const isc_netaddr_t *na,
117			 in_port_t port);
118/*
119 * Construct an isc_sockaddr_t from an isc_netaddr_t and port.
120 */
121
122int
123isc_sockaddr_pf(const isc_sockaddr_t *sockaddr);
124/*
125 * Get the protocol family of 'sockaddr'.
126 *
127 * Requires:
128 *
129 *	'sockaddr' is a valid sockaddr with an address family of AF_INET
130 *	or AF_INET6.
131 *
132 * Returns:
133 *
134 *	The protocol family of 'sockaddr', e.g. PF_INET or PF_INET6.
135 */
136
137void
138isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port);
139/*
140 * Set the port of 'sockaddr' to 'port'.
141 */
142
143in_port_t
144isc_sockaddr_getport(isc_sockaddr_t *sockaddr);
145/*
146 * Get the port stored in 'sockaddr'.
147 */
148
149isc_result_t
150isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target);
151/*
152 * Append a text representation of 'sockaddr' to the buffer 'target'.
153 * The text will include both the IP address (v4 or v6) and the port.
154 * The text is null terminated, but the terminating null is not
155 * part of the buffer's used region.
156 *
157 * Returns:
158 *	ISC_R_SUCCESS
159 *	ISC_R_NOSPACE	The text or the null termination did not fit.
160 */
161
162void
163isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size);
164/*
165 * Format a human-readable representation of the socket address '*sa'
166 * into the character array 'array', which is of size 'size'.
167 * The resulting string is guaranteed to be null-terminated.
168 */
169
170isc_boolean_t
171isc_sockaddr_ismulticast(isc_sockaddr_t *sa);
172/*
173 * Returns ISC_TRUE if the address is a multicast address.
174 */
175
176isc_boolean_t
177isc_sockaddr_isexperimental(isc_sockaddr_t *sa);
178/*
179 * Returns ISC_TRUE if the address is a experimental (CLASS E) address.
180 */
181
182isc_boolean_t
183isc_sockaddr_islinklocal(isc_sockaddr_t *sa);
184/*
185 * Returns ISC_TRUE if the address is a link local addresss.
186 */
187
188isc_boolean_t
189isc_sockaddr_issitelocal(isc_sockaddr_t *sa);
190/*
191 * Returns ISC_TRUE if the address is a sitelocal address.
192 */
193
194#define ISC_SOCKADDR_FORMATSIZE \
195	sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX#YYYYY")
196/*
197 * Minimum size of array to pass to isc_sockaddr_format().
198 */
199
200ISC_LANG_ENDDECLS
201
202#endif /* ISC_SOCKADDR_H */