"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/dns/rdata/generic/eui64_109.c" (7 Sep 2020, 4875 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 "eui64_109.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 #ifndef RDATA_GENERIC_EUI64_109_C
   13 #define RDATA_GENERIC_EUI64_109_C
   14 
   15 #include <string.h>
   16 
   17 #define RRTYPE_EUI64_ATTRIBUTES (0)
   18 
   19 static inline isc_result_t
   20 fromtext_eui64(ARGS_FROMTEXT) {
   21     isc_token_t token;
   22     unsigned char eui64[8];
   23     unsigned int l0, l1, l2, l3, l4, l5, l6, l7;
   24     int n;
   25 
   26     REQUIRE(type == dns_rdatatype_eui64);
   27 
   28     UNUSED(type);
   29     UNUSED(rdclass);
   30     UNUSED(origin);
   31     UNUSED(options);
   32     UNUSED(callbacks);
   33 
   34     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
   35                       false));
   36     n = sscanf(DNS_AS_STR(token), "%2x-%2x-%2x-%2x-%2x-%2x-%2x-%2x",
   37            &l0, &l1, &l2, &l3, &l4, &l5, &l6, &l7);
   38     if (n != 8 || l0 > 255U || l1 > 255U || l2 > 255U || l3 > 255U ||
   39         l4 > 255U || l5 > 255U || l6 > 255U || l7 > 255U)
   40         return (DNS_R_BADEUI);
   41 
   42     eui64[0] = l0;
   43     eui64[1] = l1;
   44     eui64[2] = l2;
   45     eui64[3] = l3;
   46     eui64[4] = l4;
   47     eui64[5] = l5;
   48     eui64[6] = l6;
   49     eui64[7] = l7;
   50     return (mem_tobuffer(target, eui64, sizeof(eui64)));
   51 }
   52 
   53 static inline isc_result_t
   54 totext_eui64(ARGS_TOTEXT) {
   55     char buf[sizeof("xx-xx-xx-xx-xx-xx-xx-xx")];
   56 
   57     REQUIRE(rdata->type == dns_rdatatype_eui64);
   58     REQUIRE(rdata->length == 8);
   59 
   60     UNUSED(tctx);
   61 
   62     (void)snprintf(buf, sizeof(buf),
   63                "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
   64                rdata->data[0], rdata->data[1],
   65                rdata->data[2], rdata->data[3],
   66                rdata->data[4], rdata->data[5],
   67                rdata->data[6], rdata->data[7]);
   68     return (str_totext(buf, target));
   69 }
   70 
   71 static inline isc_result_t
   72 fromwire_eui64(ARGS_FROMWIRE) {
   73     isc_region_t sregion;
   74 
   75     REQUIRE(type == dns_rdatatype_eui64);
   76 
   77     UNUSED(type);
   78     UNUSED(options);
   79     UNUSED(rdclass);
   80     UNUSED(dctx);
   81 
   82     isc_buffer_activeregion(source, &sregion);
   83     if (sregion.length != 8)
   84         return (DNS_R_FORMERR);
   85     isc_buffer_forward(source, sregion.length);
   86     return (mem_tobuffer(target, sregion.base, sregion.length));
   87 }
   88 
   89 static inline isc_result_t
   90 towire_eui64(ARGS_TOWIRE) {
   91 
   92     REQUIRE(rdata->type == dns_rdatatype_eui64);
   93     REQUIRE(rdata->length == 8);
   94 
   95     UNUSED(cctx);
   96 
   97     return (mem_tobuffer(target, rdata->data, rdata->length));
   98 }
   99 
  100 static inline int
  101 compare_eui64(ARGS_COMPARE) {
  102     isc_region_t region1;
  103     isc_region_t region2;
  104 
  105     REQUIRE(rdata1->type == rdata2->type);
  106     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  107     REQUIRE(rdata1->type == dns_rdatatype_eui64);
  108     REQUIRE(rdata1->length == 8);
  109     REQUIRE(rdata2->length == 8);
  110 
  111     dns_rdata_toregion(rdata1, &region1);
  112     dns_rdata_toregion(rdata2, &region2);
  113     return (isc_region_compare(&region1, &region2));
  114 }
  115 
  116 static inline isc_result_t
  117 fromstruct_eui64(ARGS_FROMSTRUCT) {
  118     dns_rdata_eui64_t *eui64;
  119 
  120     REQUIRE(type == dns_rdatatype_eui64);
  121     REQUIRE(((dns_rdata_eui64_t *)source) != NULL);
  122     REQUIRE(((dns_rdata_eui64_t *)source)->common.rdtype == type);
  123     REQUIRE(((dns_rdata_eui64_t *)source)->common.rdclass == rdclass);
  124 
  125     eui64 = source;
  126 
  127     UNUSED(type);
  128     UNUSED(rdclass);
  129 
  130     return (mem_tobuffer(target, eui64->eui64, sizeof(eui64->eui64)));
  131 }
  132 
  133 static inline isc_result_t
  134 tostruct_eui64(ARGS_TOSTRUCT) {
  135     dns_rdata_eui64_t *eui64;
  136 
  137     REQUIRE(((dns_rdata_eui64_t *)target) != NULL);
  138     REQUIRE(rdata->type == dns_rdatatype_eui64);
  139     REQUIRE(rdata->length == 8);
  140 
  141     eui64 = target;
  142 
  143     UNUSED(mctx);
  144 
  145     eui64->common.rdclass = rdata->rdclass;
  146     eui64->common.rdtype = rdata->type;
  147     ISC_LINK_INIT(&eui64->common, link);
  148 
  149     memmove(eui64->eui64, rdata->data, rdata->length);
  150     return (ISC_R_SUCCESS);
  151 }
  152 
  153 static inline void
  154 freestruct_eui64(ARGS_FREESTRUCT) {
  155     REQUIRE(((dns_rdata_eui64_t *)source) != NULL);
  156     REQUIRE(((dns_rdata_eui64_t *)source)->common.rdtype ==
  157         dns_rdatatype_eui64);
  158 
  159     return;
  160 }
  161 
  162 static inline isc_result_t
  163 additionaldata_eui64(ARGS_ADDLDATA) {
  164 
  165     REQUIRE(rdata->type == dns_rdatatype_eui64);
  166     REQUIRE(rdata->length == 8);
  167 
  168     UNUSED(rdata);
  169     UNUSED(add);
  170     UNUSED(arg);
  171 
  172     return (ISC_R_SUCCESS);
  173 }
  174 
  175 static inline isc_result_t
  176 digest_eui64(ARGS_DIGEST) {
  177     isc_region_t r;
  178 
  179     REQUIRE(rdata->type == dns_rdatatype_eui64);
  180     REQUIRE(rdata->length == 8);
  181 
  182     dns_rdata_toregion(rdata, &r);
  183 
  184     return ((digest)(arg, &r));
  185 }
  186 
  187 static inline bool
  188 checkowner_eui64(ARGS_CHECKOWNER) {
  189 
  190     REQUIRE(type == dns_rdatatype_eui64);
  191 
  192     UNUSED(name);
  193     UNUSED(type);
  194     UNUSED(rdclass);
  195     UNUSED(wildcard);
  196 
  197     return (true);
  198 }
  199 
  200 static inline bool
  201 checknames_eui64(ARGS_CHECKNAMES) {
  202 
  203     REQUIRE(rdata->type == dns_rdatatype_eui64);
  204     REQUIRE(rdata->length == 8);
  205 
  206     UNUSED(rdata);
  207     UNUSED(owner);
  208     UNUSED(bad);
  209 
  210     return (true);
  211 }
  212 
  213 static inline int
  214 casecompare_eui64(ARGS_COMPARE) {
  215     return (compare_eui64(rdata1, rdata2));
  216 }
  217 
  218 #endif  /* RDATA_GENERIC_EUI64_109_C */