"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/dns/rdata/generic/l64_106.c" (7 Sep 2020, 5005 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 "l64_106.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_L64_106_C
   13 #define RDATA_GENERIC_L64_106_C
   14 
   15 #include <string.h>
   16 
   17 #include <isc/net.h>
   18 
   19 #define RRTYPE_L64_ATTRIBUTES (0)
   20 
   21 static inline isc_result_t
   22 fromtext_l64(ARGS_FROMTEXT) {
   23     isc_token_t token;
   24     unsigned char locator[NS_LOCATORSZ];
   25 
   26     REQUIRE(type == dns_rdatatype_l64);
   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_number,
   35                       false));
   36     if (token.value.as_ulong > 0xffffU)
   37         RETTOK(ISC_R_RANGE);
   38     RETERR(uint16_tobuffer(token.value.as_ulong, target));
   39 
   40     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
   41                       false));
   42 
   43     if (locator_pton(DNS_AS_STR(token), locator) != 1)
   44         RETTOK(DNS_R_SYNTAX);
   45     return (mem_tobuffer(target, locator, NS_LOCATORSZ));
   46 }
   47 
   48 static inline isc_result_t
   49 totext_l64(ARGS_TOTEXT) {
   50     isc_region_t region;
   51     char buf[sizeof("xxxx:xxxx:xxxx:xxxx")];
   52     unsigned short num;
   53 
   54     REQUIRE(rdata->type == dns_rdatatype_l64);
   55     REQUIRE(rdata->length == 10);
   56 
   57     UNUSED(tctx);
   58 
   59     dns_rdata_toregion(rdata, &region);
   60     num = uint16_fromregion(&region);
   61     isc_region_consume(&region, 2);
   62     snprintf(buf, sizeof(buf), "%u", num);
   63     RETERR(str_totext(buf, target));
   64 
   65     RETERR(str_totext(" ", target));
   66 
   67     snprintf(buf, sizeof(buf), "%x:%x:%x:%x",
   68          region.base[0]<<8 | region.base[1],
   69          region.base[2]<<8 | region.base[3],
   70          region.base[4]<<8 | region.base[5],
   71          region.base[6]<<8 | region.base[7]);
   72     return (str_totext(buf, target));
   73 }
   74 
   75 static inline isc_result_t
   76 fromwire_l64(ARGS_FROMWIRE) {
   77     isc_region_t sregion;
   78 
   79     REQUIRE(type == dns_rdatatype_l64);
   80 
   81     UNUSED(type);
   82     UNUSED(options);
   83     UNUSED(rdclass);
   84     UNUSED(dctx);
   85 
   86     isc_buffer_activeregion(source, &sregion);
   87     if (sregion.length != 10)
   88         return (DNS_R_FORMERR);
   89     isc_buffer_forward(source, sregion.length);
   90     return (mem_tobuffer(target, sregion.base, sregion.length));
   91 }
   92 
   93 static inline isc_result_t
   94 towire_l64(ARGS_TOWIRE) {
   95 
   96     REQUIRE(rdata->type == dns_rdatatype_l64);
   97     REQUIRE(rdata->length == 10);
   98 
   99     UNUSED(cctx);
  100 
  101     return (mem_tobuffer(target, rdata->data, rdata->length));
  102 }
  103 
  104 static inline int
  105 compare_l64(ARGS_COMPARE) {
  106     isc_region_t region1;
  107     isc_region_t region2;
  108 
  109     REQUIRE(rdata1->type == rdata2->type);
  110     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  111     REQUIRE(rdata1->type == dns_rdatatype_l64);
  112     REQUIRE(rdata1->length == 10);
  113     REQUIRE(rdata2->length == 10);
  114 
  115     dns_rdata_toregion(rdata1, &region1);
  116     dns_rdata_toregion(rdata2, &region2);
  117     return (isc_region_compare(&region1, &region2));
  118 }
  119 
  120 static inline isc_result_t
  121 fromstruct_l64(ARGS_FROMSTRUCT) {
  122     dns_rdata_l64_t *l64;
  123 
  124     REQUIRE(type == dns_rdatatype_l64);
  125     REQUIRE(((dns_rdata_l64_t *)source) != NULL);
  126     REQUIRE(((dns_rdata_l64_t *)source)->common.rdtype == type);
  127     REQUIRE(((dns_rdata_l64_t *)source)->common.rdclass == rdclass);
  128 
  129     l64 = source;
  130 
  131     UNUSED(type);
  132     UNUSED(rdclass);
  133 
  134     RETERR(uint16_tobuffer(l64->pref, target));
  135     return (mem_tobuffer(target, l64->l64, sizeof(l64->l64)));
  136 }
  137 
  138 static inline isc_result_t
  139 tostruct_l64(ARGS_TOSTRUCT) {
  140     isc_region_t region;
  141     dns_rdata_l64_t *l64;
  142 
  143     REQUIRE(((dns_rdata_l64_t *)target) != NULL);
  144     REQUIRE(rdata->type == dns_rdatatype_l64);
  145     REQUIRE(rdata->length == 10);
  146 
  147     l64 = target;
  148 
  149     UNUSED(mctx);
  150 
  151     l64->common.rdclass = rdata->rdclass;
  152     l64->common.rdtype = rdata->type;
  153     ISC_LINK_INIT(&l64->common, link);
  154 
  155     dns_rdata_toregion(rdata, &region);
  156     l64->pref = uint16_fromregion(&region);
  157     memmove(l64->l64, region.base, region.length);
  158     return (ISC_R_SUCCESS);
  159 }
  160 
  161 static inline void
  162 freestruct_l64(ARGS_FREESTRUCT) {
  163     REQUIRE(((dns_rdata_l64_t *)source) != NULL);
  164     REQUIRE(((dns_rdata_l64_t *)source)->common.rdtype ==
  165         dns_rdatatype_l64);
  166 
  167     return;
  168 }
  169 
  170 static inline isc_result_t
  171 additionaldata_l64(ARGS_ADDLDATA) {
  172 
  173     REQUIRE(rdata->type == dns_rdatatype_l64);
  174     REQUIRE(rdata->length == 10);
  175 
  176     UNUSED(rdata);
  177     UNUSED(add);
  178     UNUSED(arg);
  179 
  180     return (ISC_R_SUCCESS);
  181 }
  182 
  183 static inline isc_result_t
  184 digest_l64(ARGS_DIGEST) {
  185     isc_region_t r;
  186 
  187     REQUIRE(rdata->type == dns_rdatatype_l64);
  188     REQUIRE(rdata->length == 10);
  189 
  190     dns_rdata_toregion(rdata, &r);
  191 
  192     return ((digest)(arg, &r));
  193 }
  194 
  195 static inline bool
  196 checkowner_l64(ARGS_CHECKOWNER) {
  197 
  198     REQUIRE(type == dns_rdatatype_l64);
  199 
  200     UNUSED(name);
  201     UNUSED(type);
  202     UNUSED(rdclass);
  203     UNUSED(wildcard);
  204 
  205     return (true);
  206 }
  207 
  208 static inline bool
  209 checknames_l64(ARGS_CHECKNAMES) {
  210 
  211     REQUIRE(rdata->type == dns_rdatatype_l64);
  212     REQUIRE(rdata->length == 10);
  213 
  214     UNUSED(rdata);
  215     UNUSED(owner);
  216     UNUSED(bad);
  217 
  218     return (true);
  219 }
  220 
  221 static inline int
  222 casecompare_l64(ARGS_COMPARE) {
  223     return (compare_l64(rdata1, rdata2));
  224 }
  225 
  226 #endif  /* RDATA_GENERIC_L64_106_C */