etc/services - sync with NetBSD-8
[minix.git] / external / bsd / bind / dist / bin / named / lwaddr.c
blob8fc8a16945c014a6fc946c8b28e58af83d2062f2
1 /* $NetBSD: lwaddr.c,v 1.5 2014/12/10 04:37:51 christos Exp $ */
3 /*
4 * Copyright (C) 2004, 2005, 2007, 2008, 2014 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000, 2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: lwaddr.c,v 1.10 2008/01/11 23:46:56 tbox Exp */
22 /*! \file */
24 #include <config.h>
26 #include <string.h>
28 #include <isc/result.h>
29 #include <isc/netaddr.h>
30 #include <isc/sockaddr.h>
32 #include <lwres/lwres.h>
34 #include <named/lwaddr.h>
36 /*%
37 * Convert addresses from lwres to isc format.
39 isc_result_t
40 lwaddr_netaddr_fromlwresaddr(isc_netaddr_t *na, lwres_addr_t *la) {
41 if (la->family != LWRES_ADDRTYPE_V4 && la->family != LWRES_ADDRTYPE_V6)
42 return (ISC_R_FAMILYNOSUPPORT);
44 if (la->family == LWRES_ADDRTYPE_V4) {
45 struct in_addr ina;
46 memmove(&ina.s_addr, la->address, 4);
47 isc_netaddr_fromin(na, &ina);
48 } else {
49 struct in6_addr ina6;
50 memmove(&ina6.s6_addr, la->address, 16);
51 isc_netaddr_fromin6(na, &ina6);
53 return (ISC_R_SUCCESS);
56 isc_result_t
57 lwaddr_sockaddr_fromlwresaddr(isc_sockaddr_t *sa, lwres_addr_t *la,
58 in_port_t port)
60 isc_netaddr_t na;
61 isc_result_t result;
63 result = lwaddr_netaddr_fromlwresaddr(&na, la);
64 if (result != ISC_R_SUCCESS)
65 return (result);
66 isc_sockaddr_fromnetaddr(sa, &na, port);
67 return (ISC_R_SUCCESS);
70 /*%
71 * Convert addresses from isc to lwres format.
74 isc_result_t
75 lwaddr_lwresaddr_fromnetaddr(lwres_addr_t *la, isc_netaddr_t *na) {
76 if (na->family != AF_INET && na->family != AF_INET6)
77 return (ISC_R_FAMILYNOSUPPORT);
79 if (na->family == AF_INET) {
80 la->family = LWRES_ADDRTYPE_V4;
81 la->length = 4;
82 memmove(la->address, &na->type.in, 4);
83 } else {
84 la->family = LWRES_ADDRTYPE_V6;
85 la->length = 16;
86 memmove(la->address, &na->type.in6, 16);
88 return (ISC_R_SUCCESS);
91 isc_result_t
92 lwaddr_lwresaddr_fromsockaddr(lwres_addr_t *la, isc_sockaddr_t *sa) {
93 isc_netaddr_t na;
94 isc_netaddr_fromsockaddr(&na, sa);
95 return (lwaddr_lwresaddr_fromnetaddr(la, &na));