Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / eui48_108.c
blob2ae26e2dda1e01bfcb13c2eb9f7f7382ae0ba5d1
1 /* $NetBSD: eui48_108.c,v 1.1.1.4 2014/12/10 03:34:42 christos Exp $ */
3 /*
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
22 #include <string.h>
24 #define RRTYPE_EUI48_ATTRIBUTES (0)
26 static inline isc_result_t
27 fromtext_eui48(ARGS_FROMTEXT) {
28 isc_token_t token;
29 unsigned char eui48[6];
30 unsigned int l0, l1, l2, l3, l4, l5;
31 int n;
33 REQUIRE(type == 108);
35 UNUSED(type);
36 UNUSED(rdclass);
37 UNUSED(origin);
38 UNUSED(options);
39 UNUSED(callbacks);
41 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
42 ISC_FALSE));
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);
49 eui48[0] = l0;
50 eui48[1] = l1;
51 eui48[2] = l2;
52 eui48[3] = l3;
53 eui48[4] = l4;
54 eui48[5] = l5;
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);
65 UNUSED(tctx);
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) {
75 isc_region_t sregion;
77 REQUIRE(type == 108);
79 UNUSED(type);
80 UNUSED(options);
81 UNUSED(rdclass);
82 UNUSED(dctx);
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);
97 UNUSED(cctx);
99 return (mem_tobuffer(target, rdata->data, rdata->length));
102 static inline int
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, &region1);
114 dns_rdata_toregion(rdata2, &region2);
115 return (isc_region_compare(&region1, &region2));
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);
127 UNUSED(type);
128 UNUSED(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);
141 UNUSED(mctx);
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);
151 static inline void
152 freestruct_eui48(ARGS_FREESTRUCT) {
153 dns_rdata_eui48_t *eui48 = source;
155 REQUIRE(source != NULL);
156 REQUIRE(eui48->common.rdtype == 108);
158 return;
161 static inline isc_result_t
162 additionaldata_eui48(ARGS_ADDLDATA) {
164 REQUIRE(rdata->type == 108);
165 REQUIRE(rdata->length == 6);
167 UNUSED(rdata);
168 UNUSED(add);
169 UNUSED(arg);
171 return (ISC_R_SUCCESS);
174 static inline isc_result_t
175 digest_eui48(ARGS_DIGEST) {
176 isc_region_t r;
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);
191 UNUSED(name);
192 UNUSED(type);
193 UNUSED(rdclass);
194 UNUSED(wildcard);
196 return (ISC_TRUE);
199 static inline isc_boolean_t
200 checknames_eui48(ARGS_CHECKNAMES) {
202 REQUIRE(rdata->type == 108);
203 REQUIRE(rdata->length == 6);
205 UNUSED(rdata);
206 UNUSED(owner);
207 UNUSED(bad);
209 return (ISC_TRUE);
212 static inline int
213 casecompare_eui48(ARGS_COMPARE) {
214 return (compare_eui48(rdata1, rdata2));
217 #endif /* RDATA_GENERIC_EUI48_108_C */