2 * Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
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.
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.
17 #ifndef RDATA_GENERIC_L64_106_C
18 #define RDATA_GENERIC_L64_106_C
24 #define RRTYPE_L64_ATTRIBUTES (0)
26 static inline isc_result_t
27 fromtext_l64(ARGS_FROMTEXT) {
29 unsigned char locator[NS_LOCATORSZ];
31 REQUIRE(type == dns_rdatatype_l64);
39 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
41 if (token.value.as_ulong > 0xffffU)
43 RETERR(uint16_tobuffer(token.value.as_ulong, target));
45 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
48 if (locator_pton(DNS_AS_STR(token), locator) != 1)
50 return (mem_tobuffer(target, locator, NS_LOCATORSZ));
53 static inline isc_result_t
54 totext_l64(ARGS_TOTEXT) {
56 char buf[sizeof("xxxx:xxxx:xxxx:xxxx")];
59 REQUIRE(rdata->type == dns_rdatatype_l64);
60 REQUIRE(rdata->length == 10);
64 dns_rdata_toregion(rdata, ®ion);
65 num = uint16_fromregion(®ion);
66 isc_region_consume(®ion, 2);
67 sprintf(buf, "%u", num);
68 RETERR(str_totext(buf, target));
70 RETERR(str_totext(" ", target));
72 sprintf(buf, "%x:%x:%x:%x",
73 region.base[0]<<8 | region.base[1],
74 region.base[2]<<8 | region.base[3],
75 region.base[4]<<8 | region.base[5],
76 region.base[6]<<8 | region.base[7]);
77 return (str_totext(buf, target));
80 static inline isc_result_t
81 fromwire_l64(ARGS_FROMWIRE) {
84 REQUIRE(type == dns_rdatatype_l64);
91 isc_buffer_activeregion(source, &sregion);
92 if (sregion.length != 10)
93 return (DNS_R_FORMERR);
94 isc_buffer_forward(source, sregion.length);
95 return (mem_tobuffer(target, sregion.base, sregion.length));
98 static inline isc_result_t
99 towire_l64(ARGS_TOWIRE) {
101 REQUIRE(rdata->type == dns_rdatatype_l64);
102 REQUIRE(rdata->length == 10);
106 return (mem_tobuffer(target, rdata->data, rdata->length));
110 compare_l64(ARGS_COMPARE) {
111 isc_region_t region1;
112 isc_region_t region2;
114 REQUIRE(rdata1->type == rdata2->type);
115 REQUIRE(rdata1->rdclass == rdata2->rdclass);
116 REQUIRE(rdata1->type == dns_rdatatype_l64);
117 REQUIRE(rdata1->length == 10);
118 REQUIRE(rdata2->length == 10);
120 dns_rdata_toregion(rdata1, ®ion1);
121 dns_rdata_toregion(rdata2, ®ion2);
122 return (isc_region_compare(®ion1, ®ion2));
125 static inline isc_result_t
126 fromstruct_l64(ARGS_FROMSTRUCT) {
127 dns_rdata_l64_t *l64 = source;
129 REQUIRE(type == dns_rdatatype_l64);
130 REQUIRE(source != NULL);
131 REQUIRE(l64->common.rdtype == type);
132 REQUIRE(l64->common.rdclass == rdclass);
137 RETERR(uint16_tobuffer(l64->pref, target));
138 return (mem_tobuffer(target, l64->l64, sizeof(l64->l64)));
141 static inline isc_result_t
142 tostruct_l64(ARGS_TOSTRUCT) {
144 dns_rdata_l64_t *l64 = target;
146 REQUIRE(rdata->type == dns_rdatatype_l64);
147 REQUIRE(target != NULL);
148 REQUIRE(rdata->length == 10);
152 l64->common.rdclass = rdata->rdclass;
153 l64->common.rdtype = rdata->type;
154 ISC_LINK_INIT(&l64->common, link);
156 dns_rdata_toregion(rdata, ®ion);
157 l64->pref = uint16_fromregion(®ion);
158 memmove(l64->l64, region.base, region.length);
159 return (ISC_R_SUCCESS);
163 freestruct_l64(ARGS_FREESTRUCT) {
164 dns_rdata_l64_t *l64 = source;
166 REQUIRE(source != NULL);
167 REQUIRE(l64->common.rdtype == dns_rdatatype_l64);
172 static inline isc_result_t
173 additionaldata_l64(ARGS_ADDLDATA) {
175 REQUIRE(rdata->type == dns_rdatatype_l64);
176 REQUIRE(rdata->length == 10);
182 return (ISC_R_SUCCESS);
185 static inline isc_result_t
186 digest_l64(ARGS_DIGEST) {
189 REQUIRE(rdata->type == dns_rdatatype_l64);
190 REQUIRE(rdata->length == 10);
192 dns_rdata_toregion(rdata, &r);
194 return ((digest)(arg, &r));
197 static inline isc_boolean_t
198 checkowner_l64(ARGS_CHECKOWNER) {
200 REQUIRE(type == dns_rdatatype_l64);
210 static inline isc_boolean_t
211 checknames_l64(ARGS_CHECKNAMES) {
213 REQUIRE(rdata->type == dns_rdatatype_l64);
214 REQUIRE(rdata->length == 10);
224 casecompare_l64(ARGS_COMPARE) {
225 return (compare_l64(rdata1, rdata2));
228 #endif /* RDATA_GENERIC_L64_106_C */