1 /* $NetBSD: aaaa_28.c,v 1.5 2014/12/10 04:37:59 christos Exp $ */
4 * Copyright (C) 2004, 2005, 2007, 2009, 2014 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2002 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: aaaa_28.c,v 1.47 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */
26 #ifndef RDATA_IN_1_AAAA_28_C
27 #define RDATA_IN_1_AAAA_28_C
31 #define RRTYPE_AAAA_ATTRIBUTES (0)
33 static inline isc_result_t
34 fromtext_in_aaaa(ARGS_FROMTEXT
) {
36 unsigned char addr
[16];
40 REQUIRE(rdclass
== 1);
48 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
51 if (inet_pton(AF_INET6
, DNS_AS_STR(token
), addr
) != 1)
52 RETTOK(DNS_R_BADAAAA
);
53 isc_buffer_availableregion(target
, ®ion
);
54 if (region
.length
< 16)
55 return (ISC_R_NOSPACE
);
56 memmove(region
.base
, addr
, 16);
57 isc_buffer_add(target
, 16);
58 return (ISC_R_SUCCESS
);
61 static inline isc_result_t
62 totext_in_aaaa(ARGS_TOTEXT
) {
67 REQUIRE(rdata
->type
== 28);
68 REQUIRE(rdata
->rdclass
== 1);
69 REQUIRE(rdata
->length
== 16);
71 dns_rdata_toregion(rdata
, ®ion
);
72 return (inet_totext(AF_INET6
, ®ion
, target
));
75 static inline isc_result_t
76 fromwire_in_aaaa(ARGS_FROMWIRE
) {
81 REQUIRE(rdclass
== 1);
88 isc_buffer_activeregion(source
, &sregion
);
89 isc_buffer_availableregion(target
, &tregion
);
90 if (sregion
.length
< 16)
91 return (ISC_R_UNEXPECTEDEND
);
92 if (tregion
.length
< 16)
93 return (ISC_R_NOSPACE
);
95 memmove(tregion
.base
, sregion
.base
, 16);
96 isc_buffer_forward(source
, 16);
97 isc_buffer_add(target
, 16);
98 return (ISC_R_SUCCESS
);
101 static inline isc_result_t
102 towire_in_aaaa(ARGS_TOWIRE
) {
107 REQUIRE(rdata
->type
== 28);
108 REQUIRE(rdata
->rdclass
== 1);
109 REQUIRE(rdata
->length
== 16);
111 isc_buffer_availableregion(target
, ®ion
);
112 if (region
.length
< rdata
->length
)
113 return (ISC_R_NOSPACE
);
114 memmove(region
.base
, rdata
->data
, rdata
->length
);
115 isc_buffer_add(target
, 16);
116 return (ISC_R_SUCCESS
);
120 compare_in_aaaa(ARGS_COMPARE
) {
124 REQUIRE(rdata1
->type
== rdata2
->type
);
125 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
126 REQUIRE(rdata1
->type
== 28);
127 REQUIRE(rdata1
->rdclass
== 1);
128 REQUIRE(rdata1
->length
== 16);
129 REQUIRE(rdata2
->length
== 16);
131 dns_rdata_toregion(rdata1
, &r1
);
132 dns_rdata_toregion(rdata2
, &r2
);
133 return (isc_region_compare(&r1
, &r2
));
136 static inline isc_result_t
137 fromstruct_in_aaaa(ARGS_FROMSTRUCT
) {
138 dns_rdata_in_aaaa_t
*aaaa
= source
;
141 REQUIRE(rdclass
== 1);
142 REQUIRE(source
!= NULL
);
143 REQUIRE(aaaa
->common
.rdtype
== type
);
144 REQUIRE(aaaa
->common
.rdclass
== rdclass
);
149 return (mem_tobuffer(target
, aaaa
->in6_addr
.s6_addr
, 16));
152 static inline isc_result_t
153 tostruct_in_aaaa(ARGS_TOSTRUCT
) {
154 dns_rdata_in_aaaa_t
*aaaa
= target
;
157 REQUIRE(rdata
->type
== 28);
158 REQUIRE(rdata
->rdclass
== 1);
159 REQUIRE(target
!= NULL
);
160 REQUIRE(rdata
->length
== 16);
164 aaaa
->common
.rdclass
= rdata
->rdclass
;
165 aaaa
->common
.rdtype
= rdata
->type
;
166 ISC_LINK_INIT(&aaaa
->common
, link
);
168 dns_rdata_toregion(rdata
, &r
);
169 INSIST(r
.length
== 16);
170 memmove(aaaa
->in6_addr
.s6_addr
, r
.base
, 16);
172 return (ISC_R_SUCCESS
);
176 freestruct_in_aaaa(ARGS_FREESTRUCT
) {
177 dns_rdata_in_aaaa_t
*aaaa
= source
;
179 REQUIRE(source
!= NULL
);
180 REQUIRE(aaaa
->common
.rdclass
== 1);
181 REQUIRE(aaaa
->common
.rdtype
== 28);
186 static inline isc_result_t
187 additionaldata_in_aaaa(ARGS_ADDLDATA
) {
188 REQUIRE(rdata
->type
== 28);
189 REQUIRE(rdata
->rdclass
== 1);
195 return (ISC_R_SUCCESS
);
198 static inline isc_result_t
199 digest_in_aaaa(ARGS_DIGEST
) {
202 REQUIRE(rdata
->type
== 28);
203 REQUIRE(rdata
->rdclass
== 1);
205 dns_rdata_toregion(rdata
, &r
);
207 return ((digest
)(arg
, &r
));
210 static inline isc_boolean_t
211 checkowner_in_aaaa(ARGS_CHECKOWNER
) {
214 REQUIRE(rdclass
== 1);
219 return (dns_name_ishostname(name
, wildcard
));
222 static inline isc_boolean_t
223 checknames_in_aaaa(ARGS_CHECKNAMES
) {
225 REQUIRE(rdata
->type
== 28);
226 REQUIRE(rdata
->rdclass
== 1);
236 casecompare_in_aaaa(ARGS_COMPARE
) {
237 return (compare_in_aaaa(rdata1
, rdata2
));
239 #endif /* RDATA_IN_1_AAAA_28_C */