1 /* $NetBSD: l64_106.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_L64_106_C
20 #define RDATA_GENERIC_L64_106_C
26 #define RRTYPE_L64_ATTRIBUTES (0)
28 static inline isc_result_t
29 fromtext_l64(ARGS_FROMTEXT
) {
31 unsigned char locator
[NS_LOCATORSZ
];
41 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
43 if (token
.value
.as_ulong
> 0xffffU
)
45 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
47 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
50 if (locator_pton(DNS_AS_STR(token
), locator
) != 1)
52 return (mem_tobuffer(target
, locator
, NS_LOCATORSZ
));
55 static inline isc_result_t
56 totext_l64(ARGS_TOTEXT
) {
58 char buf
[sizeof("xxxx:xxxx:xxxx:xxxx")];
61 REQUIRE(rdata
->type
== 106);
62 REQUIRE(rdata
->length
== 10);
66 dns_rdata_toregion(rdata
, ®ion
);
67 num
= uint16_fromregion(®ion
);
68 isc_region_consume(®ion
, 2);
69 sprintf(buf
, "%u", num
);
70 RETERR(str_totext(buf
, target
));
72 RETERR(str_totext(" ", target
));
74 sprintf(buf
, "%x:%x:%x:%x",
75 region
.base
[0]<<8 | region
.base
[1],
76 region
.base
[2]<<8 | region
.base
[3],
77 region
.base
[4]<<8 | region
.base
[5],
78 region
.base
[6]<<8 | region
.base
[7]);
79 return (str_totext(buf
, target
));
82 static inline isc_result_t
83 fromwire_l64(ARGS_FROMWIRE
) {
93 isc_buffer_activeregion(source
, &sregion
);
94 if (sregion
.length
!= 10)
95 return (DNS_R_FORMERR
);
96 isc_buffer_forward(source
, sregion
.length
);
97 return (mem_tobuffer(target
, sregion
.base
, sregion
.length
));
100 static inline isc_result_t
101 towire_l64(ARGS_TOWIRE
) {
103 REQUIRE(rdata
->type
== 106);
104 REQUIRE(rdata
->length
== 10);
108 return (mem_tobuffer(target
, rdata
->data
, rdata
->length
));
112 compare_l64(ARGS_COMPARE
) {
113 isc_region_t region1
;
114 isc_region_t region2
;
116 REQUIRE(rdata1
->type
== rdata2
->type
);
117 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
118 REQUIRE(rdata1
->type
== 106);
119 REQUIRE(rdata1
->length
== 10);
120 REQUIRE(rdata2
->length
== 10);
122 dns_rdata_toregion(rdata1
, ®ion1
);
123 dns_rdata_toregion(rdata2
, ®ion2
);
124 return (isc_region_compare(®ion1
, ®ion2
));
127 static inline isc_result_t
128 fromstruct_l64(ARGS_FROMSTRUCT
) {
129 dns_rdata_l64_t
*l64
= source
;
131 REQUIRE(type
== 106);
132 REQUIRE(source
!= NULL
);
133 REQUIRE(l64
->common
.rdtype
== type
);
134 REQUIRE(l64
->common
.rdclass
== rdclass
);
139 RETERR(uint16_tobuffer(l64
->pref
, target
));
140 return (mem_tobuffer(target
, l64
->l64
, sizeof(l64
->l64
)));
143 static inline isc_result_t
144 tostruct_l64(ARGS_TOSTRUCT
) {
146 dns_rdata_l64_t
*l64
= target
;
148 REQUIRE(rdata
->type
== 106);
149 REQUIRE(target
!= NULL
);
150 REQUIRE(rdata
->length
== 10);
154 l64
->common
.rdclass
= rdata
->rdclass
;
155 l64
->common
.rdtype
= rdata
->type
;
156 ISC_LINK_INIT(&l64
->common
, link
);
158 dns_rdata_toregion(rdata
, ®ion
);
159 l64
->pref
= uint16_fromregion(®ion
);
160 memmove(l64
->l64
, region
.base
, region
.length
);
161 return (ISC_R_SUCCESS
);
165 freestruct_l64(ARGS_FREESTRUCT
) {
166 dns_rdata_l64_t
*l64
= source
;
168 REQUIRE(source
!= NULL
);
169 REQUIRE(l64
->common
.rdtype
== 106);
174 static inline isc_result_t
175 additionaldata_l64(ARGS_ADDLDATA
) {
177 REQUIRE(rdata
->type
== 106);
178 REQUIRE(rdata
->length
== 10);
184 return (ISC_R_SUCCESS
);
187 static inline isc_result_t
188 digest_l64(ARGS_DIGEST
) {
191 REQUIRE(rdata
->type
== 106);
192 REQUIRE(rdata
->length
== 10);
194 dns_rdata_toregion(rdata
, &r
);
196 return ((digest
)(arg
, &r
));
199 static inline isc_boolean_t
200 checkowner_l64(ARGS_CHECKOWNER
) {
202 REQUIRE(type
== 106);
212 static inline isc_boolean_t
213 checknames_l64(ARGS_CHECKNAMES
) {
215 REQUIRE(rdata
->type
== 106);
216 REQUIRE(rdata
->length
== 10);
226 casecompare_l64(ARGS_COMPARE
) {
227 return (compare_l64(rdata1
, rdata2
));
230 #endif /* RDATA_GENERIC_L64_106_C */