"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/dns/rdata/generic/l32_105.c" (4 Sep 2020, 4889 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 "l32_105.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 9.17.2_vs_9.17.3.

    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_L32_105_C
   13 #define RDATA_GENERIC_L32_105_C
   14 
   15 #include <string.h>
   16 
   17 #include <isc/net.h>
   18 
   19 #define RRTYPE_L32_ATTRIBUTES (0)
   20 
   21 static inline isc_result_t
   22 fromtext_l32(ARGS_FROMTEXT) {
   23     isc_token_t token;
   24     struct in_addr addr;
   25     isc_region_t region;
   26 
   27     REQUIRE(type == dns_rdatatype_l32);
   28 
   29     UNUSED(type);
   30     UNUSED(rdclass);
   31     UNUSED(origin);
   32     UNUSED(options);
   33     UNUSED(callbacks);
   34 
   35     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
   36                       false));
   37     if (token.value.as_ulong > 0xffffU) {
   38         RETTOK(ISC_R_RANGE);
   39     }
   40     RETERR(uint16_tobuffer(token.value.as_ulong, target));
   41 
   42     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
   43                       false));
   44 
   45     if (inet_pton(AF_INET, DNS_AS_STR(token), &addr) != 1) {
   46         RETTOK(DNS_R_BADDOTTEDQUAD);
   47     }
   48     isc_buffer_availableregion(target, &region);
   49     if (region.length < 4) {
   50         return (ISC_R_NOSPACE);
   51     }
   52     memmove(region.base, &addr, 4);
   53     isc_buffer_add(target, 4);
   54     return (ISC_R_SUCCESS);
   55 }
   56 
   57 static inline isc_result_t
   58 totext_l32(ARGS_TOTEXT) {
   59     isc_region_t region;
   60     char buf[sizeof("65000")];
   61     unsigned short num;
   62 
   63     REQUIRE(rdata->type == dns_rdatatype_l32);
   64     REQUIRE(rdata->length == 6);
   65 
   66     UNUSED(tctx);
   67 
   68     dns_rdata_toregion(rdata, &region);
   69     num = uint16_fromregion(&region);
   70     isc_region_consume(&region, 2);
   71     snprintf(buf, sizeof(buf), "%u", num);
   72     RETERR(str_totext(buf, target));
   73 
   74     RETERR(str_totext(" ", target));
   75 
   76     return (inet_totext(AF_INET, tctx->flags, &region, target));
   77 }
   78 
   79 static inline isc_result_t
   80 fromwire_l32(ARGS_FROMWIRE) {
   81     isc_region_t sregion;
   82 
   83     REQUIRE(type == dns_rdatatype_l32);
   84 
   85     UNUSED(type);
   86     UNUSED(options);
   87     UNUSED(rdclass);
   88     UNUSED(dctx);
   89 
   90     isc_buffer_activeregion(source, &sregion);
   91     if (sregion.length != 6) {
   92         return (DNS_R_FORMERR);
   93     }
   94     isc_buffer_forward(source, sregion.length);
   95     return (mem_tobuffer(target, sregion.base, sregion.length));
   96 }
   97 
   98 static inline isc_result_t
   99 towire_l32(ARGS_TOWIRE) {
  100     REQUIRE(rdata->type == dns_rdatatype_l32);
  101     REQUIRE(rdata->length == 6);
  102 
  103     UNUSED(cctx);
  104 
  105     return (mem_tobuffer(target, rdata->data, rdata->length));
  106 }
  107 
  108 static inline int
  109 compare_l32(ARGS_COMPARE) {
  110     isc_region_t region1;
  111     isc_region_t region2;
  112 
  113     REQUIRE(rdata1->type == rdata2->type);
  114     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  115     REQUIRE(rdata1->type == dns_rdatatype_l32);
  116     REQUIRE(rdata1->length == 6);
  117     REQUIRE(rdata2->length == 6);
  118 
  119     dns_rdata_toregion(rdata1, &region1);
  120     dns_rdata_toregion(rdata2, &region2);
  121     return (isc_region_compare(&region1, &region2));
  122 }
  123 
  124 static inline isc_result_t
  125 fromstruct_l32(ARGS_FROMSTRUCT) {
  126     dns_rdata_l32_t *l32 = source;
  127     uint32_t n;
  128 
  129     REQUIRE(type == dns_rdatatype_l32);
  130     REQUIRE(l32 != NULL);
  131     REQUIRE(l32->common.rdtype == type);
  132     REQUIRE(l32->common.rdclass == rdclass);
  133 
  134     UNUSED(type);
  135     UNUSED(rdclass);
  136 
  137     RETERR(uint16_tobuffer(l32->pref, target));
  138     n = ntohl(l32->l32.s_addr);
  139     return (uint32_tobuffer(n, target));
  140 }
  141 
  142 static inline isc_result_t
  143 tostruct_l32(ARGS_TOSTRUCT) {
  144     isc_region_t region;
  145     dns_rdata_l32_t *l32 = target;
  146     uint32_t n;
  147 
  148     REQUIRE(rdata->type == dns_rdatatype_l32);
  149     REQUIRE(l32 != NULL);
  150     REQUIRE(rdata->length == 6);
  151 
  152     UNUSED(mctx);
  153 
  154     l32->common.rdclass = rdata->rdclass;
  155     l32->common.rdtype = rdata->type;
  156     ISC_LINK_INIT(&l32->common, link);
  157 
  158     dns_rdata_toregion(rdata, &region);
  159     l32->pref = uint16_fromregion(&region);
  160     n = uint32_fromregion(&region);
  161     l32->l32.s_addr = htonl(n);
  162     return (ISC_R_SUCCESS);
  163 }
  164 
  165 static inline void
  166 freestruct_l32(ARGS_FREESTRUCT) {
  167     dns_rdata_l32_t *l32 = source;
  168 
  169     REQUIRE(l32 != NULL);
  170     REQUIRE(l32->common.rdtype == dns_rdatatype_l32);
  171 
  172     return;
  173 }
  174 
  175 static inline isc_result_t
  176 additionaldata_l32(ARGS_ADDLDATA) {
  177     REQUIRE(rdata->type == dns_rdatatype_l32);
  178     REQUIRE(rdata->length == 6);
  179 
  180     UNUSED(rdata);
  181     UNUSED(add);
  182     UNUSED(arg);
  183 
  184     return (ISC_R_SUCCESS);
  185 }
  186 
  187 static inline isc_result_t
  188 digest_l32(ARGS_DIGEST) {
  189     isc_region_t r;
  190 
  191     REQUIRE(rdata->type == dns_rdatatype_l32);
  192     REQUIRE(rdata->length == 6);
  193 
  194     dns_rdata_toregion(rdata, &r);
  195 
  196     return ((digest)(arg, &r));
  197 }
  198 
  199 static inline bool
  200 checkowner_l32(ARGS_CHECKOWNER) {
  201     REQUIRE(type == dns_rdatatype_l32);
  202 
  203     UNUSED(name);
  204     UNUSED(type);
  205     UNUSED(rdclass);
  206     UNUSED(wildcard);
  207 
  208     return (true);
  209 }
  210 
  211 static inline bool
  212 checknames_l32(ARGS_CHECKNAMES) {
  213     REQUIRE(rdata->type == dns_rdatatype_l32);
  214     REQUIRE(rdata->length == 6);
  215 
  216     UNUSED(rdata);
  217     UNUSED(owner);
  218     UNUSED(bad);
  219 
  220     return (true);
  221 }
  222 
  223 static inline int
  224 casecompare_l32(ARGS_COMPARE) {
  225     return (compare_l32(rdata1, rdata2));
  226 }
  227 
  228 #endif /* RDATA_GENERIC_L32_105_C */