l32_105.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2013, 2014  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 #ifndef RDATA_GENERIC_L32_105_C
00018 #define RDATA_GENERIC_L32_105_C
00019 
00020 #include <string.h>
00021 
00022 #include <isc/net.h>
00023 
00024 #define RRTYPE_L32_ATTRIBUTES (0)
00025 
00026 static inline isc_result_t
00027 fromtext_l32(ARGS_FROMTEXT) {
00028         isc_token_t token;
00029         struct in_addr addr;
00030         isc_region_t region;
00031 
00032         REQUIRE(type == 105);
00033 
00034         UNUSED(type);
00035         UNUSED(rdclass);
00036         UNUSED(origin);
00037         UNUSED(options);
00038         UNUSED(callbacks);
00039 
00040         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00041                                       ISC_FALSE));
00042         if (token.value.as_ulong > 0xffffU)
00043                 RETTOK(ISC_R_RANGE);
00044         RETERR(uint16_tobuffer(token.value.as_ulong, target));
00045 
00046         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00047                                       ISC_FALSE));
00048 
00049         if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1)
00050                 RETTOK(DNS_R_BADDOTTEDQUAD);
00051         isc_buffer_availableregion(target, &region);
00052         if (region.length < 4)
00053                 return (ISC_R_NOSPACE);
00054         memmove(region.base, &addr, 4);
00055         isc_buffer_add(target, 4);
00056         return (ISC_R_SUCCESS);
00057 }
00058 
00059 static inline isc_result_t
00060 totext_l32(ARGS_TOTEXT) {
00061         isc_region_t region;
00062         char buf[sizeof("65000")];
00063         unsigned short num;
00064 
00065         REQUIRE(rdata->type == 105);
00066         REQUIRE(rdata->length == 6);
00067 
00068         UNUSED(tctx);
00069 
00070         dns_rdata_toregion(rdata, &region);
00071         num = uint16_fromregion(&region);
00072         isc_region_consume(&region, 2);
00073         sprintf(buf, "%u", num);
00074         RETERR(str_totext(buf, target));
00075 
00076         RETERR(str_totext(" ", target));
00077 
00078         return (inet_totext(AF_INET, &region, target));
00079 }
00080 
00081 static inline isc_result_t
00082 fromwire_l32(ARGS_FROMWIRE) {
00083         isc_region_t sregion;
00084 
00085         REQUIRE(type == 105);
00086 
00087         UNUSED(type);
00088         UNUSED(options);
00089         UNUSED(rdclass);
00090         UNUSED(dctx);
00091 
00092         isc_buffer_activeregion(source, &sregion);
00093         if (sregion.length != 6)
00094                 return (DNS_R_FORMERR);
00095         isc_buffer_forward(source, sregion.length);
00096         return (mem_tobuffer(target, sregion.base, sregion.length));
00097 }
00098 
00099 static inline isc_result_t
00100 towire_l32(ARGS_TOWIRE) {
00101 
00102         REQUIRE(rdata->type == 105);
00103         REQUIRE(rdata->length == 6);
00104 
00105         UNUSED(cctx);
00106 
00107         return (mem_tobuffer(target, rdata->data, rdata->length));
00108 }
00109 
00110 static inline int
00111 compare_l32(ARGS_COMPARE) {
00112         isc_region_t region1;
00113         isc_region_t region2;
00114 
00115         REQUIRE(rdata1->type == rdata2->type);
00116         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00117         REQUIRE(rdata1->type == 105);
00118         REQUIRE(rdata1->length == 6);
00119         REQUIRE(rdata2->length == 6);
00120 
00121         dns_rdata_toregion(rdata1, &region1);
00122         dns_rdata_toregion(rdata2, &region2);
00123         return (isc_region_compare(&region1, &region2));
00124 }
00125 
00126 static inline isc_result_t
00127 fromstruct_l32(ARGS_FROMSTRUCT) {
00128         dns_rdata_l32_t *l32 = source;
00129         isc_uint32_t n;
00130 
00131         REQUIRE(type == 105);
00132         REQUIRE(source != NULL);
00133         REQUIRE(l32->common.rdtype == type);
00134         REQUIRE(l32->common.rdclass == rdclass);
00135 
00136         UNUSED(type);
00137         UNUSED(rdclass);
00138 
00139         RETERR(uint16_tobuffer(l32->pref, target));
00140         n = ntohl(l32->l32.s_addr);
00141         return (uint32_tobuffer(n, target));
00142 }
00143 
00144 static inline isc_result_t
00145 tostruct_l32(ARGS_TOSTRUCT) {
00146         isc_region_t region;
00147         dns_rdata_l32_t *l32 = target;
00148         isc_uint32_t n;
00149 
00150         REQUIRE(rdata->type == 105);
00151         REQUIRE(target != NULL);
00152         REQUIRE(rdata->length == 6);
00153 
00154         UNUSED(mctx);
00155 
00156         l32->common.rdclass = rdata->rdclass;
00157         l32->common.rdtype = rdata->type;
00158         ISC_LINK_INIT(&l32->common, link);
00159 
00160         dns_rdata_toregion(rdata, &region);
00161         l32->pref = uint16_fromregion(&region);
00162         n = uint32_fromregion(&region);
00163         l32->l32.s_addr = htonl(n);
00164         return (ISC_R_SUCCESS);
00165 }
00166 
00167 static inline void
00168 freestruct_l32(ARGS_FREESTRUCT) {
00169         dns_rdata_l32_t *l32 = source;
00170 
00171         REQUIRE(source != NULL);
00172         REQUIRE(l32->common.rdtype == 105);
00173 
00174         return;
00175 }
00176 
00177 static inline isc_result_t
00178 additionaldata_l32(ARGS_ADDLDATA) {
00179 
00180         REQUIRE(rdata->type == 105);
00181         REQUIRE(rdata->length == 6);
00182 
00183         UNUSED(rdata);
00184         UNUSED(add);
00185         UNUSED(arg);
00186 
00187         return (ISC_R_SUCCESS);
00188 }
00189 
00190 static inline isc_result_t
00191 digest_l32(ARGS_DIGEST) {
00192         isc_region_t r;
00193 
00194         REQUIRE(rdata->type == 105);
00195         REQUIRE(rdata->length == 6);
00196 
00197         dns_rdata_toregion(rdata, &r);
00198 
00199         return ((digest)(arg, &r));
00200 }
00201 
00202 static inline isc_boolean_t
00203 checkowner_l32(ARGS_CHECKOWNER) {
00204 
00205         REQUIRE(type == 105);
00206 
00207         UNUSED(name);
00208         UNUSED(type);
00209         UNUSED(rdclass);
00210         UNUSED(wildcard);
00211 
00212         return (ISC_TRUE);
00213 }
00214 
00215 static inline isc_boolean_t
00216 checknames_l32(ARGS_CHECKNAMES) {
00217 
00218         REQUIRE(rdata->type == 105);
00219         REQUIRE(rdata->length == 6);
00220 
00221         UNUSED(rdata);
00222         UNUSED(owner);
00223         UNUSED(bad);
00224 
00225         return (ISC_TRUE);
00226 }
00227 
00228 static inline int
00229 casecompare_l32(ARGS_COMPARE) {
00230         return (compare_l32(rdata1, rdata2));
00231 }
00232 
00233 #endif  /* RDATA_GENERIC_L32_105_C */

Generated on Tue Apr 28 17:40:59 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha