"Fossies" - the Fresh Open Source Software Archive

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