"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/dns/rdata/generic/eui48_108.c" (4 Sep 2020, 4596 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.tar.xz:


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