2 * Copyright (C) 2004, 2005, 2007, 2008 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or 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.
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.
18 /* $Id: lwaddr.c,v 1.8.130.2 2008/01/11 23:46:27 tbox Exp $ */
26 #include <isc/result.h>
27 #include <isc/netaddr.h>
28 #include <isc/sockaddr.h>
30 #include <lwres/lwres.h>
32 #include <named/lwaddr.h>
35 * Convert addresses from lwres to isc format.
38 lwaddr_netaddr_fromlwresaddr(isc_netaddr_t
*na
, lwres_addr_t
*la
) {
39 if (la
->family
!= LWRES_ADDRTYPE_V4
&& la
->family
!= LWRES_ADDRTYPE_V6
)
40 return (ISC_R_FAMILYNOSUPPORT
);
42 if (la
->family
== LWRES_ADDRTYPE_V4
) {
44 memcpy(&ina
.s_addr
, la
->address
, 4);
45 isc_netaddr_fromin(na
, &ina
);
48 memcpy(&ina6
.s6_addr
, la
->address
, 16);
49 isc_netaddr_fromin6(na
, &ina6
);
51 return (ISC_R_SUCCESS
);
55 lwaddr_sockaddr_fromlwresaddr(isc_sockaddr_t
*sa
, lwres_addr_t
*la
,
61 result
= lwaddr_netaddr_fromlwresaddr(&na
, la
);
62 if (result
!= ISC_R_SUCCESS
)
64 isc_sockaddr_fromnetaddr(sa
, &na
, port
);
65 return (ISC_R_SUCCESS
);
69 * Convert addresses from isc to lwres format.
73 lwaddr_lwresaddr_fromnetaddr(lwres_addr_t
*la
, isc_netaddr_t
*na
) {
74 if (na
->family
!= AF_INET
&& na
->family
!= AF_INET6
)
75 return (ISC_R_FAMILYNOSUPPORT
);
77 if (na
->family
== AF_INET
) {
78 la
->family
= LWRES_ADDRTYPE_V4
;
80 memcpy(la
->address
, &na
->type
.in
, 4);
82 la
->family
= LWRES_ADDRTYPE_V6
;
84 memcpy(la
->address
, &na
->type
.in6
, 16);
86 return (ISC_R_SUCCESS
);
90 lwaddr_lwresaddr_fromsockaddr(lwres_addr_t
*la
, isc_sockaddr_t
*sa
) {
92 isc_netaddr_fromsockaddr(&na
, sa
);
93 return (lwaddr_lwresaddr_fromnetaddr(la
, &na
));