2
2
* Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3
* Copyright (C) 1999-2001 Internet Software Consortium.
3
* Copyright (C) 1999-2002 Internet Software Consortium.
5
5
* Permission to use, copy, modify, and distribute this software for any
6
6
* purpose with or without fee is hereby granted, provided that the above
37
37
if (a->family != b->family)
38
38
return (ISC_FALSE);
40
if (a->zone != b->zone)
40
43
switch (a->family) {
42
45
if (a->type.in.s_addr != b->type.in.s_addr)
43
46
return (ISC_FALSE);
46
if (memcmp(&a->type.in6, &b->type.in6, sizeof a->type.in6)
49
if (memcmp(&a->type.in6, &b->type.in6,
50
sizeof(a->type.in6)) != 0 ||
48
52
return (ISC_FALSE);
114
121
isc_netaddr_totext(const isc_netaddr_t *netaddr, isc_buffer_t *target) {
115
char abuf[sizeof "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255"];
122
char abuf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")];
123
char zbuf[sizeof("%4294967295")];
116
124
unsigned int alen;
119
129
REQUIRE(netaddr != NULL);
121
r = inet_ntop(netaddr->family, &netaddr->type, abuf, sizeof abuf);
131
switch (netaddr->family) {
133
type = &netaddr->type.in;
136
type = &netaddr->type.in6;
139
return (ISC_R_FAILURE);
141
r = inet_ntop(netaddr->family, type, abuf, sizeof(abuf));
123
143
return (ISC_R_FAILURE);
125
145
alen = strlen(abuf);
126
146
INSIST(alen < sizeof(abuf));
128
if (alen > isc_buffer_availablelength(target))
149
if (netaddr->family == AF_INET6 && netaddr->zone != 0) {
150
zlen = snprintf(zbuf, sizeof(zbuf), "%%%u", netaddr->zone);
152
return (ISC_R_FAILURE);
153
INSIST((unsigned int)zlen < sizeof(zbuf));
156
if (alen + zlen > isc_buffer_availablelength(target))
129
157
return (ISC_R_NOSPACE);
131
159
isc_buffer_putmem(target, (unsigned char *)abuf, alen);
160
isc_buffer_putmem(target, (unsigned char *)zbuf, zlen);
133
162
return (ISC_R_SUCCESS);
137
isc_netaddr_format(isc_netaddr_t *na, char *array, unsigned int size) {
166
isc_netaddr_format(const isc_netaddr_t *na, char *array, unsigned int size) {
138
167
isc_result_t result;
139
168
isc_buffer_t buf;
207
236
isc_netaddr_fromin(isc_netaddr_t *netaddr, const struct in_addr *ina) {
208
memset(netaddr, 0, sizeof *netaddr);
237
memset(netaddr, 0, sizeof(*netaddr));
209
238
netaddr->family = AF_INET;
210
239
netaddr->type.in = *ina;
214
243
isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6) {
215
memset(netaddr, 0, sizeof *netaddr);
244
memset(netaddr, 0, sizeof(*netaddr));
216
245
netaddr->family = AF_INET6;
217
246
netaddr->type.in6 = *ina6;
250
isc_netaddr_setzone(isc_netaddr_t *netaddr, isc_uint32_t zone) {
251
/* we currently only support AF_INET6. */
252
REQUIRE(netaddr->family == AF_INET6);
254
netaddr->zone = zone;
258
isc_netaddr_getzone(const isc_netaddr_t *netaddr) {
259
return (netaddr->zone);
221
263
isc_netaddr_fromsockaddr(isc_netaddr_t *t, const isc_sockaddr_t *s) {
222
264
int family = s->type.sa.sa_family;
223
265
t->family = family;
224
266
switch (family) {
226
268
t->type.in = s->type.sin.sin_addr;
229
272
memcpy(&t->type.in6, &s->type.sin6.sin6_addr, 16);
273
#ifdef ISC_PLATFORM_HAVESCOPEID
274
t->zone = s->type.sin6.sin6_scope_id;
237
285
isc_netaddr_any(isc_netaddr_t *netaddr) {
238
memset(netaddr, 0, sizeof *netaddr);
286
memset(netaddr, 0, sizeof(*netaddr));
239
287
netaddr->family = AF_INET;
240
288
netaddr->type.in.s_addr = INADDR_ANY;
244
292
isc_netaddr_any6(isc_netaddr_t *netaddr) {
245
memset(netaddr, 0, sizeof *netaddr);
293
memset(netaddr, 0, sizeof(*netaddr));
246
294
netaddr->family = AF_INET6;
247
295
netaddr->type.in6 = in6addr_any;
321
isc_netaddr_islinklocal(isc_netaddr_t *na) {
322
switch (na->family) {
326
return (ISC_TF(IN6_IS_ADDR_LINKLOCAL(&na->type.in6)));
333
isc_netaddr_issitelocal(isc_netaddr_t *na) {
334
switch (na->family) {
338
return (ISC_TF(IN6_IS_ADDR_SITELOCAL(&na->type.in6)));
273
345
isc_netaddr_fromv4mapped(isc_netaddr_t *t, const isc_netaddr_t *s) {
274
346
isc_netaddr_t *src;