"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/bin/named/lwaddr.c" (7 Sep 2020, 2146 Bytes) of package /linux/misc/dns/bind9/9.11.23/bind-9.11.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "lwaddr.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 /* $Id: lwaddr.c,v 1.10 2008/01/11 23:46:56 tbox Exp $ */
   13 
   14 /*! \file */
   15 
   16 #include <config.h>
   17 
   18 #include <string.h>
   19 
   20 #include <isc/result.h>
   21 #include <isc/netaddr.h>
   22 #include <isc/sockaddr.h>
   23 
   24 #include <lwres/lwres.h>
   25 
   26 #include <named/lwaddr.h>
   27 
   28 /*%
   29  * Convert addresses from lwres to isc format.
   30  */
   31 isc_result_t
   32 lwaddr_netaddr_fromlwresaddr(isc_netaddr_t *na, lwres_addr_t *la) {
   33     if (la->family != LWRES_ADDRTYPE_V4 && la->family != LWRES_ADDRTYPE_V6)
   34         return (ISC_R_FAMILYNOSUPPORT);
   35 
   36     if (la->family == LWRES_ADDRTYPE_V4) {
   37         struct in_addr ina;
   38         memmove(&ina.s_addr, la->address, 4);
   39         isc_netaddr_fromin(na, &ina);
   40     } else {
   41         struct in6_addr ina6;
   42         memmove(&ina6.s6_addr, la->address, 16);
   43         isc_netaddr_fromin6(na, &ina6);
   44     }
   45     return (ISC_R_SUCCESS);
   46 }
   47 
   48 isc_result_t
   49 lwaddr_sockaddr_fromlwresaddr(isc_sockaddr_t *sa, lwres_addr_t *la,
   50                   in_port_t port)
   51 {
   52     isc_netaddr_t na;
   53     isc_result_t result;
   54 
   55     result = lwaddr_netaddr_fromlwresaddr(&na, la);
   56     if (result != ISC_R_SUCCESS)
   57         return (result);
   58     isc_sockaddr_fromnetaddr(sa, &na, port);
   59     return (ISC_R_SUCCESS);
   60 }
   61 
   62 /*%
   63  * Convert addresses from isc to lwres format.
   64  */
   65 
   66 isc_result_t
   67 lwaddr_lwresaddr_fromnetaddr(lwres_addr_t *la, isc_netaddr_t *na) {
   68     if (na->family != AF_INET && na->family != AF_INET6)
   69         return (ISC_R_FAMILYNOSUPPORT);
   70 
   71     if (na->family == AF_INET) {
   72         la->family = LWRES_ADDRTYPE_V4;
   73         la->length = 4;
   74         memmove(la->address, &na->type.in, 4);
   75     } else {
   76         la->family = LWRES_ADDRTYPE_V6;
   77         la->length = 16;
   78         memmove(la->address, &na->type.in6, 16);
   79     }
   80     return (ISC_R_SUCCESS);
   81 }
   82 
   83 isc_result_t
   84 lwaddr_lwresaddr_fromsockaddr(lwres_addr_t *la, isc_sockaddr_t *sa) {
   85     isc_netaddr_t na;
   86     isc_netaddr_fromsockaddr(&na, sa);
   87     return (lwaddr_lwresaddr_fromnetaddr(la, &na));
   88 }