1 /* $NetBSD: eui48_108.c,v 1.1.1.4 2014/12/10 03:34:42 christos Exp $ */
4 * Copyright (C) 2013, 2014 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 #ifndef RDATA_GENERIC_EUI48_108_C
20 #define RDATA_GENERIC_EUI48_108_C
24 #define RRTYPE_EUI48_ATTRIBUTES (0)
26 static inline isc_result_t
27 fromtext_eui48(ARGS_FROMTEXT
) {
29 unsigned char eui48
[6];
30 unsigned int l0
, l1
, l2
, l3
, l4
, l5
;
41 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
43 n
= sscanf(DNS_AS_STR(token
), "%2x-%2x-%2x-%2x-%2x-%2x",
44 &l0
, &l1
, &l2
, &l3
, &l4
, &l5
);
45 if (n
!= 6 || l0
> 255U || l1
> 255U || l2
> 255U || l3
> 255U ||
46 l4
> 255U || l5
> 255U)
47 return (DNS_R_BADEUI
);
55 return (mem_tobuffer(target
, eui48
, sizeof(eui48
)));
58 static inline isc_result_t
59 totext_eui48(ARGS_TOTEXT
) {
60 char buf
[sizeof("xx-xx-xx-xx-xx-xx")];
62 REQUIRE(rdata
->type
== 108);
63 REQUIRE(rdata
->length
== 6);
67 (void)snprintf(buf
, sizeof(buf
), "%02x-%02x-%02x-%02x-%02x-%02x",
68 rdata
->data
[0], rdata
->data
[1], rdata
->data
[2],
69 rdata
->data
[3], rdata
->data
[4], rdata
->data
[5]);
70 return (str_totext(buf
, target
));
73 static inline isc_result_t
74 fromwire_eui48(ARGS_FROMWIRE
) {
84 isc_buffer_activeregion(source
, &sregion
);
85 if (sregion
.length
!= 6)
86 return (DNS_R_FORMERR
);
87 isc_buffer_forward(source
, sregion
.length
);
88 return (mem_tobuffer(target
, sregion
.base
, sregion
.length
));
91 static inline isc_result_t
92 towire_eui48(ARGS_TOWIRE
) {
94 REQUIRE(rdata
->type
== 108);
95 REQUIRE(rdata
->length
== 6);
99 return (mem_tobuffer(target
, rdata
->data
, rdata
->length
));
103 compare_eui48(ARGS_COMPARE
) {
104 isc_region_t region1
;
105 isc_region_t region2
;
107 REQUIRE(rdata1
->type
== rdata2
->type
);
108 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
109 REQUIRE(rdata1
->type
== 108);
110 REQUIRE(rdata1
->length
== 6);
111 REQUIRE(rdata2
->length
== 6);
113 dns_rdata_toregion(rdata1
, ®ion1
);
114 dns_rdata_toregion(rdata2
, ®ion2
);
115 return (isc_region_compare(®ion1
, ®ion2
));
118 static inline isc_result_t
119 fromstruct_eui48(ARGS_FROMSTRUCT
) {
120 dns_rdata_eui48_t
*eui48
= source
;
122 REQUIRE(type
== 108);
123 REQUIRE(source
!= NULL
);
124 REQUIRE(eui48
->common
.rdtype
== type
);
125 REQUIRE(eui48
->common
.rdclass
== rdclass
);
130 return (mem_tobuffer(target
, eui48
->eui48
, sizeof(eui48
->eui48
)));
133 static inline isc_result_t
134 tostruct_eui48(ARGS_TOSTRUCT
) {
135 dns_rdata_eui48_t
*eui48
= target
;
137 REQUIRE(rdata
->type
== 108);
138 REQUIRE(target
!= NULL
);
139 REQUIRE(rdata
->length
== 6);
143 eui48
->common
.rdclass
= rdata
->rdclass
;
144 eui48
->common
.rdtype
= rdata
->type
;
145 ISC_LINK_INIT(&eui48
->common
, link
);
147 memmove(eui48
->eui48
, rdata
->data
, rdata
->length
);
148 return (ISC_R_SUCCESS
);
152 freestruct_eui48(ARGS_FREESTRUCT
) {
153 dns_rdata_eui48_t
*eui48
= source
;
155 REQUIRE(source
!= NULL
);
156 REQUIRE(eui48
->common
.rdtype
== 108);
161 static inline isc_result_t
162 additionaldata_eui48(ARGS_ADDLDATA
) {
164 REQUIRE(rdata
->type
== 108);
165 REQUIRE(rdata
->length
== 6);
171 return (ISC_R_SUCCESS
);
174 static inline isc_result_t
175 digest_eui48(ARGS_DIGEST
) {
178 REQUIRE(rdata
->type
== 108);
179 REQUIRE(rdata
->length
== 6);
181 dns_rdata_toregion(rdata
, &r
);
183 return ((digest
)(arg
, &r
));
186 static inline isc_boolean_t
187 checkowner_eui48(ARGS_CHECKOWNER
) {
189 REQUIRE(type
== 108);
199 static inline isc_boolean_t
200 checknames_eui48(ARGS_CHECKNAMES
) {
202 REQUIRE(rdata
->type
== 108);
203 REQUIRE(rdata
->length
== 6);
213 casecompare_eui48(ARGS_COMPARE
) {
214 return (compare_eui48(rdata1
, rdata2
));
217 #endif /* RDATA_GENERIC_EUI48_108_C */