1 /* $NetBSD: eui64_109.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_EUI64_109_C
20 #define RDATA_GENERIC_EUI64_109_C
24 #define RRTYPE_EUI64_ATTRIBUTES (0)
26 static inline isc_result_t
27 fromtext_eui64(ARGS_FROMTEXT
) {
29 unsigned char eui64
[8];
30 unsigned int l0
, l1
, l2
, l3
, l4
, l5
, l6
, l7
;
41 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
43 n
= sscanf(DNS_AS_STR(token
), "%2x-%2x-%2x-%2x-%2x-%2x-%2x-%2x",
44 &l0
, &l1
, &l2
, &l3
, &l4
, &l5
, &l6
, &l7
);
45 if (n
!= 8 || l0
> 255U || l1
> 255U || l2
> 255U || l3
> 255U ||
46 l4
> 255U || l5
> 255U || l6
> 255U || l7
> 255U)
47 return (DNS_R_BADEUI
);
57 return (mem_tobuffer(target
, eui64
, sizeof(eui64
)));
60 static inline isc_result_t
61 totext_eui64(ARGS_TOTEXT
) {
62 char buf
[sizeof("xx-xx-xx-xx-xx-xx-xx-xx")];
64 REQUIRE(rdata
->type
== 109);
65 REQUIRE(rdata
->length
== 8);
69 (void)snprintf(buf
, sizeof(buf
),
70 "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
71 rdata
->data
[0], rdata
->data
[1],
72 rdata
->data
[2], rdata
->data
[3],
73 rdata
->data
[4], rdata
->data
[5],
74 rdata
->data
[6], rdata
->data
[7]);
75 return (str_totext(buf
, target
));
78 static inline isc_result_t
79 fromwire_eui64(ARGS_FROMWIRE
) {
89 isc_buffer_activeregion(source
, &sregion
);
90 if (sregion
.length
!= 8)
91 return (DNS_R_FORMERR
);
92 isc_buffer_forward(source
, sregion
.length
);
93 return (mem_tobuffer(target
, sregion
.base
, sregion
.length
));
96 static inline isc_result_t
97 towire_eui64(ARGS_TOWIRE
) {
99 REQUIRE(rdata
->type
== 109);
100 REQUIRE(rdata
->length
== 8);
104 return (mem_tobuffer(target
, rdata
->data
, rdata
->length
));
108 compare_eui64(ARGS_COMPARE
) {
109 isc_region_t region1
;
110 isc_region_t region2
;
112 REQUIRE(rdata1
->type
== rdata2
->type
);
113 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
114 REQUIRE(rdata1
->type
== 109);
115 REQUIRE(rdata1
->length
== 8);
116 REQUIRE(rdata2
->length
== 8);
118 dns_rdata_toregion(rdata1
, ®ion1
);
119 dns_rdata_toregion(rdata2
, ®ion2
);
120 return (isc_region_compare(®ion1
, ®ion2
));
123 static inline isc_result_t
124 fromstruct_eui64(ARGS_FROMSTRUCT
) {
125 dns_rdata_eui64_t
*eui64
= source
;
127 REQUIRE(type
== 109);
128 REQUIRE(source
!= NULL
);
129 REQUIRE(eui64
->common
.rdtype
== type
);
130 REQUIRE(eui64
->common
.rdclass
== rdclass
);
135 return (mem_tobuffer(target
, eui64
->eui64
, sizeof(eui64
->eui64
)));
138 static inline isc_result_t
139 tostruct_eui64(ARGS_TOSTRUCT
) {
140 dns_rdata_eui64_t
*eui64
= target
;
142 REQUIRE(rdata
->type
== 109);
143 REQUIRE(target
!= NULL
);
144 REQUIRE(rdata
->length
== 8);
148 eui64
->common
.rdclass
= rdata
->rdclass
;
149 eui64
->common
.rdtype
= rdata
->type
;
150 ISC_LINK_INIT(&eui64
->common
, link
);
152 memmove(eui64
->eui64
, rdata
->data
, rdata
->length
);
153 return (ISC_R_SUCCESS
);
157 freestruct_eui64(ARGS_FREESTRUCT
) {
158 dns_rdata_eui64_t
*eui64
= source
;
160 REQUIRE(source
!= NULL
);
161 REQUIRE(eui64
->common
.rdtype
== 109);
166 static inline isc_result_t
167 additionaldata_eui64(ARGS_ADDLDATA
) {
169 REQUIRE(rdata
->type
== 109);
170 REQUIRE(rdata
->length
== 8);
176 return (ISC_R_SUCCESS
);
179 static inline isc_result_t
180 digest_eui64(ARGS_DIGEST
) {
183 REQUIRE(rdata
->type
== 109);
184 REQUIRE(rdata
->length
== 8);
186 dns_rdata_toregion(rdata
, &r
);
188 return ((digest
)(arg
, &r
));
191 static inline isc_boolean_t
192 checkowner_eui64(ARGS_CHECKOWNER
) {
194 REQUIRE(type
== 109);
204 static inline isc_boolean_t
205 checknames_eui64(ARGS_CHECKNAMES
) {
207 REQUIRE(rdata
->type
== 109);
208 REQUIRE(rdata
->length
== 8);
218 casecompare_eui64(ARGS_COMPARE
) {
219 return (compare_eui64(rdata1
, rdata2
));
222 #endif /* RDATA_GENERIC_EUI64_109_C */