"Fossies" - the Fresh Open Source Software Archive

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