Annotation of src/external/mpl/bind/dist/lib/dns/rdata/generic/eui48_108.c, Revision 1.1.1.4
1.1 christos 1: /* $NetBSD$ */
2:
3: /*
4: * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5: *
6: * This Source Code Form is subject to the terms of the Mozilla Public
7: * License, v. 2.0. If a copy of the MPL was not distributed with this
8: * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9: *
10: * See the COPYRIGHT file distributed with this work for additional
11: * information regarding copyright ownership.
12: */
13:
14: #ifndef RDATA_GENERIC_EUI48_108_C
15: #define RDATA_GENERIC_EUI48_108_C
16:
17: #include <string.h>
18:
19: #define RRTYPE_EUI48_ATTRIBUTES (0)
20:
21: static inline isc_result_t
22: fromtext_eui48(ARGS_FROMTEXT) {
23: isc_token_t token;
24: unsigned char eui48[6];
25: unsigned int l0, l1, l2, l3, l4, l5;
26: int n;
27:
28: REQUIRE(type == dns_rdatatype_eui48);
29:
30: UNUSED(type);
31: UNUSED(rdclass);
32: UNUSED(origin);
33: UNUSED(options);
34: UNUSED(callbacks);
35:
36: RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
1.1.1.2 christos 37: false));
1.1.1.4 ! christos 38: n = sscanf(DNS_AS_STR(token), "%2x-%2x-%2x-%2x-%2x-%2x", &l0, &l1, &l2,
! 39: &l3, &l4, &l5);
1.1 christos 40: if (n != 6 || l0 > 255U || l1 > 255U || l2 > 255U || l3 > 255U ||
41: l4 > 255U || l5 > 255U)
1.1.1.4 ! christos 42: {
1.1 christos 43: return (DNS_R_BADEUI);
1.1.1.4 ! christos 44: }
1.1 christos 45:
46: eui48[0] = l0;
47: eui48[1] = l1;
48: eui48[2] = l2;
49: eui48[3] = l3;
50: eui48[4] = l4;
51: eui48[5] = l5;
52: return (mem_tobuffer(target, eui48, sizeof(eui48)));
53: }
54:
55: static inline isc_result_t
56: totext_eui48(ARGS_TOTEXT) {
57: char buf[sizeof("xx-xx-xx-xx-xx-xx")];
58:
59: REQUIRE(rdata->type == dns_rdatatype_eui48);
60: REQUIRE(rdata->length == 6);
61:
62: UNUSED(tctx);
63:
64: (void)snprintf(buf, sizeof(buf), "%02x-%02x-%02x-%02x-%02x-%02x",
65: rdata->data[0], rdata->data[1], rdata->data[2],
66: rdata->data[3], rdata->data[4], rdata->data[5]);
67: return (str_totext(buf, target));
68: }
69:
70: static inline isc_result_t
71: fromwire_eui48(ARGS_FROMWIRE) {
72: isc_region_t sregion;
73:
74: REQUIRE(type == dns_rdatatype_eui48);
75:
76: UNUSED(type);
77: UNUSED(options);
78: UNUSED(rdclass);
79: UNUSED(dctx);
80:
81: isc_buffer_activeregion(source, &sregion);
1.1.1.4 ! christos 82: if (sregion.length != 6) {
1.1 christos 83: return (DNS_R_FORMERR);
1.1.1.4 ! christos 84: }
1.1 christos 85: isc_buffer_forward(source, sregion.length);
86: return (mem_tobuffer(target, sregion.base, sregion.length));
87: }
88:
89: static inline isc_result_t
90: towire_eui48(ARGS_TOWIRE) {
91: REQUIRE(rdata->type == dns_rdatatype_eui48);
92: REQUIRE(rdata->length == 6);
93:
94: UNUSED(cctx);
95:
96: return (mem_tobuffer(target, rdata->data, rdata->length));
97: }
98:
99: static inline int
100: compare_eui48(ARGS_COMPARE) {
101: isc_region_t region1;
102: isc_region_t region2;
103:
104: REQUIRE(rdata1->type == rdata2->type);
105: REQUIRE(rdata1->rdclass == rdata2->rdclass);
106: REQUIRE(rdata1->type == dns_rdatatype_eui48);
107: REQUIRE(rdata1->length == 6);
108: REQUIRE(rdata2->length == 6);
109:
110: dns_rdata_toregion(rdata1, ®ion1);
111: dns_rdata_toregion(rdata2, ®ion2);
112: return (isc_region_compare(®ion1, ®ion2));
113: }
114:
115: static inline isc_result_t
116: fromstruct_eui48(ARGS_FROMSTRUCT) {
117: dns_rdata_eui48_t *eui48 = source;
118:
119: REQUIRE(type == dns_rdatatype_eui48);
1.1.1.3 christos 120: REQUIRE(eui48 != NULL);
1.1 christos 121: REQUIRE(eui48->common.rdtype == type);
122: REQUIRE(eui48->common.rdclass == rdclass);
123:
124: UNUSED(type);
125: UNUSED(rdclass);
126:
127: return (mem_tobuffer(target, eui48->eui48, sizeof(eui48->eui48)));
128: }
129:
130: static inline isc_result_t
131: tostruct_eui48(ARGS_TOSTRUCT) {
132: dns_rdata_eui48_t *eui48 = target;
133:
134: REQUIRE(rdata->type == dns_rdatatype_eui48);
1.1.1.3 christos 135: REQUIRE(eui48 != NULL);
1.1 christos 136: REQUIRE(rdata->length == 6);
137:
138: UNUSED(mctx);
139:
140: eui48->common.rdclass = rdata->rdclass;
141: eui48->common.rdtype = rdata->type;
142: ISC_LINK_INIT(&eui48->common, link);
143:
144: memmove(eui48->eui48, rdata->data, rdata->length);
145: return (ISC_R_SUCCESS);
146: }
147:
148: static inline void
149: freestruct_eui48(ARGS_FREESTRUCT) {
150: dns_rdata_eui48_t *eui48 = source;
151:
1.1.1.3 christos 152: REQUIRE(eui48 != NULL);
1.1 christos 153: REQUIRE(eui48->common.rdtype == dns_rdatatype_eui48);
154:
155: return;
156: }
157:
158: static inline isc_result_t
159: additionaldata_eui48(ARGS_ADDLDATA) {
160: REQUIRE(rdata->type == dns_rdatatype_eui48);
161: REQUIRE(rdata->length == 6);
162:
163: UNUSED(rdata);
164: UNUSED(add);
165: UNUSED(arg);
166:
167: return (ISC_R_SUCCESS);
168: }
169:
170: static inline isc_result_t
171: digest_eui48(ARGS_DIGEST) {
172: isc_region_t r;
173:
174: REQUIRE(rdata->type == dns_rdatatype_eui48);
175: REQUIRE(rdata->length == 6);
176:
177: dns_rdata_toregion(rdata, &r);
178:
179: return ((digest)(arg, &r));
180: }
181:
1.1.1.2 christos 182: static inline bool
1.1 christos 183: checkowner_eui48(ARGS_CHECKOWNER) {
184: REQUIRE(type == dns_rdatatype_eui48);
185:
186: UNUSED(name);
187: UNUSED(type);
188: UNUSED(rdclass);
189: UNUSED(wildcard);
190:
1.1.1.2 christos 191: return (true);
1.1 christos 192: }
193:
1.1.1.2 christos 194: static inline bool
1.1 christos 195: checknames_eui48(ARGS_CHECKNAMES) {
196: REQUIRE(rdata->type == dns_rdatatype_eui48);
197: REQUIRE(rdata->length == 6);
198:
199: UNUSED(rdata);
200: UNUSED(owner);
201: UNUSED(bad);
202:
1.1.1.2 christos 203: return (true);
1.1 christos 204: }
205:
206: static inline int
207: casecompare_eui48(ARGS_COMPARE) {
208: return (compare_eui48(rdata1, rdata2));
209: }
210:
1.1.1.4 ! christos 211: #endif /* RDATA_GENERIC_EUI48_108_C */
CVSweb <webmaster@jp.NetBSD.org>