1 /*
2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3 *
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.
7 *
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.
15 */
16
17 #ifndef RDATA_GENERIC_EUI64_109_C
18 #define RDATA_GENERIC_EUI64_109_C
19
20 #include <string.h>
21
22 static inline isc_result_t
totext_eui64(ARGS_TOTEXT)23 totext_eui64(ARGS_TOTEXT) {
24 char buf[sizeof("xx-xx-xx-xx-xx-xx-xx-xx")];
25
26 REQUIRE(rdata->type == dns_rdatatype_eui64);
27 REQUIRE(rdata->length == 8);
28
29 UNUSED(tctx);
30
31 (void)snprintf(buf, sizeof(buf),
32 "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
33 rdata->data[0], rdata->data[1],
34 rdata->data[2], rdata->data[3],
35 rdata->data[4], rdata->data[5],
36 rdata->data[6], rdata->data[7]);
37 return (isc_str_tobuffer(buf, target));
38 }
39
40 static inline isc_result_t
fromwire_eui64(ARGS_FROMWIRE)41 fromwire_eui64(ARGS_FROMWIRE) {
42 isc_region_t sregion;
43
44 REQUIRE(type == dns_rdatatype_eui64);
45
46 UNUSED(type);
47 UNUSED(options);
48 UNUSED(rdclass);
49 UNUSED(dctx);
50
51 isc_buffer_activeregion(source, &sregion);
52 if (sregion.length != 8)
53 return (DNS_R_FORMERR);
54 isc_buffer_forward(source, sregion.length);
55 return (isc_mem_tobuffer(target, sregion.base, sregion.length));
56 }
57
58 static inline isc_result_t
towire_eui64(ARGS_TOWIRE)59 towire_eui64(ARGS_TOWIRE) {
60
61 REQUIRE(rdata->type == dns_rdatatype_eui64);
62 REQUIRE(rdata->length == 8);
63
64 UNUSED(cctx);
65
66 return (isc_mem_tobuffer(target, rdata->data, rdata->length));
67 }
68
69 #endif /* RDATA_GENERIC_EUI64_109_C */
70