sockaddr.h 3.74 KB
Newer Older
Bob Halley's avatar
Bob Halley committed
1
/*
David Lawrence's avatar
David Lawrence committed
2
 * Copyright (C) 1998-2000  Internet Software Consortium.
3
 *
Bob Halley's avatar
Bob Halley committed
4
5
6
 * 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.
7
 *
8
9
10
11
12
13
14
15
 * 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.
Bob Halley's avatar
Bob Halley committed
16
17
 */

18
/* $Id: sockaddr.h,v 1.33 2000/08/09 18:55:54 gson Exp $ */
David Lawrence's avatar
David Lawrence committed
19

Bob Halley's avatar
Bob Halley committed
20
21
22
#ifndef ISC_SOCKADDR_H
#define ISC_SOCKADDR_H 1

Bob Halley's avatar
Bob Halley committed
23
#include <isc/lang.h>
24
#include <isc/net.h>
25
#include <isc/types.h>
Bob Halley's avatar
Bob Halley committed
26

27
struct isc_sockaddr {
Bob Halley's avatar
Bob Halley committed
28
	union {
Bob Halley's avatar
Bob Halley committed
29
30
31
		struct sockaddr		sa;
		struct sockaddr_in	sin;
		struct sockaddr_in6	sin6;
Bob Halley's avatar
Bob Halley committed
32
	}				type;
Bob Halley's avatar
Bob Halley committed
33
	unsigned int			length;		/* XXXRTH beginning? */
Bob Halley's avatar
Bob Halley committed
34
	ISC_LINK(struct isc_sockaddr)	link;
35
};
Bob Halley's avatar
Bob Halley committed
36

Bob Halley's avatar
Bob Halley committed
37
38
typedef ISC_LIST(struct isc_sockaddr)	isc_sockaddrlist_t;

39
40
ISC_LANG_BEGINDECLS

Michael Graff's avatar
Michael Graff committed
41
isc_boolean_t
42
isc_sockaddr_equal(const isc_sockaddr_t *a, const isc_sockaddr_t *b);
Bob Halley's avatar
Bob Halley committed
43

44
isc_boolean_t
45
isc_sockaddr_eqaddr(const isc_sockaddr_t *a, const isc_sockaddr_t *b);
46

47
48
49
50
isc_boolean_t
isc_sockaddr_eqaddrprefix(const isc_sockaddr_t *a, const isc_sockaddr_t *b,
			  unsigned int prefixlen);

Bob Halley's avatar
Bob Halley committed
51
unsigned int
52
isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, isc_boolean_t address_only);
Michael Graff's avatar
Michael Graff committed
53

54
55
56
57
58
59
void
isc_sockaddr_any(isc_sockaddr_t *sockaddr);

void
isc_sockaddr_any6(isc_sockaddr_t *sockaddr);

60
61
62
void
isc_sockaddr_anyofpf(isc_sockaddr_t *sockaddr, int family);

Bob Halley's avatar
Bob Halley committed
63
void
64
isc_sockaddr_fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
65
		    in_port_t port);
Bob Halley's avatar
Bob Halley committed
66
67

void
68
isc_sockaddr_fromin6(isc_sockaddr_t *sockaddr, const struct in6_addr *ina6,
69
		     in_port_t port);
Bob Halley's avatar
Bob Halley committed
70

71
void
72
isc_sockaddr_v6fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
73
		      in_port_t port);
74

75
76
77
78
void
isc_sockaddr_fromnetaddr(isc_sockaddr_t *sockaddr, const isc_netaddr_t *na,
			 in_port_t port);

79
int
80
isc_sockaddr_pf(const isc_sockaddr_t *sockaddr);
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Get the protocol family of 'sockaddr'.
 *
 * Requires:
 *
 *	'sockaddr' is a valid sockaddr with an address family of AF_INET
 *	or AF_INET6.
 *
 * Returns:
 *
 *	The protocol family of 'sockaddr', e.g. PF_INET or PF_INET6.
 */

Bob Halley's avatar
Bob Halley committed
94
95
96
97
98
99
void
isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port);
/*
 * Set the port of 'sockaddr' to 'port'.
 */

David Lawrence's avatar
David Lawrence committed
100
101
102
103
104
105
in_port_t
isc_sockaddr_getport(isc_sockaddr_t *sockaddr);
/*
 * Get the port stored in 'sockaddr'.
 */

106
107
108
109
110
isc_result_t
isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target);
/*
 * Append a text representation of 'sockaddr' to the buffer 'target'.
 * The text will include both the IP address (v4 or v6) and the port.
111
112
 * The text is null terminated, but the terminating null is not
 * part of the buffer's used region.
113
114
115
 *
 * Returns:
 *	ISC_R_SUCCESS
116
 *	ISC_R_NOSPACE	The text or the null termination did not fit.
117
 */
Mark Andrews's avatar
Mark Andrews committed
118

119
120
121
122
123
124
125
126
void
isc_sockaddr_format(isc_sockaddr_t *sa, char *array, unsigned int size);
/*
 * Format a human-readable representation of the socket address '*sa'
 * into the character array 'array', which is of size 'size'.
 * The resulting string is guaranteed to be null-terminated.
 */

127
128
129
130
131
132
isc_boolean_t
isc_sockaddr_ismulticast(isc_sockaddr_t *sa);
/*
 * Returns ISC_TRUE if the address is a multicast address
 */

133
134
#define ISC_SOCKADDR_FORMATSIZE \
	sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX#YYYYY")
135
136
137
/*
 * Minimum size of array to pass to isc_sockaddr_format().
 */
138

Bob Halley's avatar
Bob Halley committed
139
140
ISC_LANG_ENDDECLS

Bob Halley's avatar
Bob Halley committed
141
#endif /* ISC_SOCKADDR_H */