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

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