2 * Copyright (C) 2013, 2014 Internet Systems Consortium, Inc. ("ISC")
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
17 #ifndef RDATA_GENERIC_EUI48_108_C
18 #define RDATA_GENERIC_EUI48_108_C
22 #define RRTYPE_EUI48_ATTRIBUTES (0)
24 static inline isc_result_t
25 fromtext_eui48(ARGS_FROMTEXT) {
27 unsigned char eui48[6];
28 unsigned int l0, l1, l2, l3, l4, l5;
39 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
41 n = sscanf(DNS_AS_STR(token), "%2x-%2x-%2x-%2x-%2x-%2x",
42 &l0, &l1, &l2, &l3, &l4, &l5);
43 if (n != 6 || l0 > 255U || l1 > 255U || l2 > 255U || l3 > 255U ||
44 l4 > 255U || l5 > 255U)
45 return (DNS_R_BADEUI);
53 return (mem_tobuffer(target, eui48, sizeof(eui48)));
56 static inline isc_result_t
57 totext_eui48(ARGS_TOTEXT) {
58 char buf[sizeof("xx-xx-xx-xx-xx-xx")];
60 REQUIRE(rdata->type == 108);
61 REQUIRE(rdata->length == 6);
65 (void)snprintf(buf, sizeof(buf), "%02x-%02x-%02x-%02x-%02x-%02x",
66 rdata->data[0], rdata->data[1], rdata->data[2],
67 rdata->data[3], rdata->data[4], rdata->data[5]);
68 return (str_totext(buf, target));
71 static inline isc_result_t
72 fromwire_eui48(ARGS_FROMWIRE) {
82 isc_buffer_activeregion(source, &sregion);
83 if (sregion.length != 6)
84 return (DNS_R_FORMERR);
85 isc_buffer_forward(source, sregion.length);
86 return (mem_tobuffer(target, sregion.base, sregion.length));
89 static inline isc_result_t
90 towire_eui48(ARGS_TOWIRE) {
92 REQUIRE(rdata->type == 108);
93 REQUIRE(rdata->length == 6);
97 return (mem_tobuffer(target, rdata->data, rdata->length));
101 compare_eui48(ARGS_COMPARE) {
102 isc_region_t region1;
103 isc_region_t region2;
105 REQUIRE(rdata1->type == rdata2->type);
106 REQUIRE(rdata1->rdclass == rdata2->rdclass);
107 REQUIRE(rdata1->type == 108);
108 REQUIRE(rdata1->length == 6);
109 REQUIRE(rdata2->length == 6);
111 dns_rdata_toregion(rdata1, ®ion1);
112 dns_rdata_toregion(rdata2, ®ion2);
113 return (isc_region_compare(®ion1, ®ion2));
116 static inline isc_result_t
117 fromstruct_eui48(ARGS_FROMSTRUCT) {
118 dns_rdata_eui48_t *eui48 = source;
120 REQUIRE(type == 108);
121 REQUIRE(source != NULL);
122 REQUIRE(eui48->common.rdtype == type);
123 REQUIRE(eui48->common.rdclass == rdclass);
128 return (mem_tobuffer(target, eui48->eui48, sizeof(eui48->eui48)));
131 static inline isc_result_t
132 tostruct_eui48(ARGS_TOSTRUCT) {
133 dns_rdata_eui48_t *eui48 = target;
135 REQUIRE(rdata->type == 108);
136 REQUIRE(target != NULL);
137 REQUIRE(rdata->length == 6);
141 eui48->common.rdclass = rdata->rdclass;
142 eui48->common.rdtype = rdata->type;
143 ISC_LINK_INIT(&eui48->common, link);
145 memmove(eui48->eui48, rdata->data, rdata->length);
146 return (ISC_R_SUCCESS);
150 freestruct_eui48(ARGS_FREESTRUCT) {
151 dns_rdata_eui48_t *eui48 = source;
153 REQUIRE(source != NULL);
154 REQUIRE(eui48->common.rdtype == 108);
159 static inline isc_result_t
160 additionaldata_eui48(ARGS_ADDLDATA) {
162 REQUIRE(rdata->type == 108);
163 REQUIRE(rdata->length == 6);
169 return (ISC_R_SUCCESS);
172 static inline isc_result_t
173 digest_eui48(ARGS_DIGEST) {
176 REQUIRE(rdata->type == 108);
177 REQUIRE(rdata->length == 6);
179 dns_rdata_toregion(rdata, &r);
181 return ((digest)(arg, &r));
184 static inline isc_boolean_t
185 checkowner_eui48(ARGS_CHECKOWNER) {
187 REQUIRE(type == 108);
197 static inline isc_boolean_t
198 checknames_eui48(ARGS_CHECKNAMES) {
200 REQUIRE(rdata->type == 108);
201 REQUIRE(rdata->length == 6);
211 casecompare_eui48(ARGS_COMPARE) {
212 return (compare_eui48(rdata1, rdata2));
215 #endif /* RDATA_GENERIC_EUI48_108_C */