eui64_109.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_EUI64_109_C
00018 #define RDATA_GENERIC_EUI64_109_C
00019 
00020 #include <string.h>
00021 
00022 #define RRTYPE_EUI64_ATTRIBUTES (0)
00023 
00024 static inline isc_result_t
00025 fromtext_eui64(ARGS_FROMTEXT) {
00026         isc_token_t token;
00027         unsigned char eui64[8];
00028         unsigned int l0, l1, l2, l3, l4, l5, l6, l7;
00029         int n;
00030 
00031         REQUIRE(type == 109);
00032 
00033         UNUSED(type);
00034         UNUSED(rdclass);
00035         UNUSED(origin);
00036         UNUSED(options);
00037         UNUSED(callbacks);
00038 
00039         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00040                                       ISC_FALSE));
00041         n = sscanf(DNS_AS_STR(token), "%2x-%2x-%2x-%2x-%2x-%2x-%2x-%2x",
00042                    &l0, &l1, &l2, &l3, &l4, &l5, &l6, &l7);
00043         if (n != 8 || l0 > 255U || l1 > 255U || l2 > 255U || l3 > 255U ||
00044             l4 > 255U || l5 > 255U || l6 > 255U || l7 > 255U)
00045                 return (DNS_R_BADEUI);
00046 
00047         eui64[0] = l0;
00048         eui64[1] = l1;
00049         eui64[2] = l2;
00050         eui64[3] = l3;
00051         eui64[4] = l4;
00052         eui64[5] = l5;
00053         eui64[6] = l6;
00054         eui64[7] = l7;
00055         return (mem_tobuffer(target, eui64, sizeof(eui64)));
00056 }
00057 
00058 static inline isc_result_t
00059 totext_eui64(ARGS_TOTEXT) {
00060         char buf[sizeof("xx-xx-xx-xx-xx-xx-xx-xx")];
00061 
00062         REQUIRE(rdata->type == 109);
00063         REQUIRE(rdata->length == 8);
00064 
00065         UNUSED(tctx);
00066 
00067         (void)snprintf(buf, sizeof(buf),
00068                        "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
00069                        rdata->data[0], rdata->data[1],
00070                        rdata->data[2], rdata->data[3],
00071                        rdata->data[4], rdata->data[5],
00072                        rdata->data[6], rdata->data[7]);
00073         return (str_totext(buf, target));
00074 }
00075 
00076 static inline isc_result_t
00077 fromwire_eui64(ARGS_FROMWIRE) {
00078         isc_region_t sregion;
00079 
00080         REQUIRE(type == 109);
00081 
00082         UNUSED(type);
00083         UNUSED(options);
00084         UNUSED(rdclass);
00085         UNUSED(dctx);
00086 
00087         isc_buffer_activeregion(source, &sregion);
00088         if (sregion.length != 8)
00089                 return (DNS_R_FORMERR);
00090         isc_buffer_forward(source, sregion.length);
00091         return (mem_tobuffer(target, sregion.base, sregion.length));
00092 }
00093 
00094 static inline isc_result_t
00095 towire_eui64(ARGS_TOWIRE) {
00096 
00097         REQUIRE(rdata->type == 109);
00098         REQUIRE(rdata->length == 8);
00099 
00100         UNUSED(cctx);
00101 
00102         return (mem_tobuffer(target, rdata->data, rdata->length));
00103 }
00104 
00105 static inline int
00106 compare_eui64(ARGS_COMPARE) {
00107         isc_region_t region1;
00108         isc_region_t region2;
00109 
00110         REQUIRE(rdata1->type == rdata2->type);
00111         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00112         REQUIRE(rdata1->type == 109);
00113         REQUIRE(rdata1->length == 8);
00114         REQUIRE(rdata2->length == 8);
00115 
00116         dns_rdata_toregion(rdata1, &region1);
00117         dns_rdata_toregion(rdata2, &region2);
00118         return (isc_region_compare(&region1, &region2));
00119 }
00120 
00121 static inline isc_result_t
00122 fromstruct_eui64(ARGS_FROMSTRUCT) {
00123         dns_rdata_eui64_t *eui64 = source;
00124 
00125         REQUIRE(type == 109);
00126         REQUIRE(source != NULL);
00127         REQUIRE(eui64->common.rdtype == type);
00128         REQUIRE(eui64->common.rdclass == rdclass);
00129 
00130         UNUSED(type);
00131         UNUSED(rdclass);
00132 
00133         return (mem_tobuffer(target, eui64->eui64, sizeof(eui64->eui64)));
00134 }
00135 
00136 static inline isc_result_t
00137 tostruct_eui64(ARGS_TOSTRUCT) {
00138         dns_rdata_eui64_t *eui64 = target;
00139 
00140         REQUIRE(rdata->type == 109);
00141         REQUIRE(target != NULL);
00142         REQUIRE(rdata->length == 8);
00143 
00144         UNUSED(mctx);
00145 
00146         eui64->common.rdclass = rdata->rdclass;
00147         eui64->common.rdtype = rdata->type;
00148         ISC_LINK_INIT(&eui64->common, link);
00149 
00150         memmove(eui64->eui64, rdata->data, rdata->length);
00151         return (ISC_R_SUCCESS);
00152 }
00153 
00154 static inline void
00155 freestruct_eui64(ARGS_FREESTRUCT) {
00156         dns_rdata_eui64_t *eui64 = source;
00157 
00158         REQUIRE(source != NULL);
00159         REQUIRE(eui64->common.rdtype == 109);
00160 
00161         return;
00162 }
00163 
00164 static inline isc_result_t
00165 additionaldata_eui64(ARGS_ADDLDATA) {
00166 
00167         REQUIRE(rdata->type == 109);
00168         REQUIRE(rdata->length == 8);
00169 
00170         UNUSED(rdata);
00171         UNUSED(add);
00172         UNUSED(arg);
00173 
00174         return (ISC_R_SUCCESS);
00175 }
00176 
00177 static inline isc_result_t
00178 digest_eui64(ARGS_DIGEST) {
00179         isc_region_t r;
00180 
00181         REQUIRE(rdata->type == 109);
00182         REQUIRE(rdata->length == 8);
00183 
00184         dns_rdata_toregion(rdata, &r);
00185 
00186         return ((digest)(arg, &r));
00187 }
00188 
00189 static inline isc_boolean_t
00190 checkowner_eui64(ARGS_CHECKOWNER) {
00191 
00192         REQUIRE(type == 109);
00193 
00194         UNUSED(name);
00195         UNUSED(type);
00196         UNUSED(rdclass);
00197         UNUSED(wildcard);
00198 
00199         return (ISC_TRUE);
00200 }
00201 
00202 static inline isc_boolean_t
00203 checknames_eui64(ARGS_CHECKNAMES) {
00204 
00205         REQUIRE(rdata->type == 109);
00206         REQUIRE(rdata->length == 8);
00207 
00208         UNUSED(rdata);
00209         UNUSED(owner);
00210         UNUSED(bad);
00211 
00212         return (ISC_TRUE);
00213 }
00214 
00215 static inline int
00216 casecompare_eui64(ARGS_COMPARE) {
00217         return (compare_eui64(rdata1, rdata2));
00218 }
00219 
00220 #endif  /* RDATA_GENERIC_EUI64_109_C */

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