2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: aaaa_28.c,v 1.36.2.1 2004/03/09 06:11:36 marka Exp $ */
20 /* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */
24 #ifndef RDATA_IN_1_AAAA_28_C
25 #define RDATA_IN_1_AAAA_28_C
29 #define RRTYPE_AAAA_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_in_aaaa(ARGS_FROMTEXT
) {
34 unsigned char addr
[16];
38 REQUIRE(rdclass
== 1);
46 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
49 if (inet_pton(AF_INET6
, token
.value
.as_pointer
, addr
) != 1)
50 RETTOK(DNS_R_BADAAAA
);
51 isc_buffer_availableregion(target
, ®ion
);
52 if (region
.length
< 16)
53 return (ISC_R_NOSPACE
);
54 memcpy(region
.base
, addr
, 16);
55 isc_buffer_add(target
, 16);
56 return (ISC_R_SUCCESS
);
59 static inline isc_result_t
60 totext_in_aaaa(ARGS_TOTEXT
) {
65 REQUIRE(rdata
->type
== 28);
66 REQUIRE(rdata
->rdclass
== 1);
67 REQUIRE(rdata
->length
== 16);
69 dns_rdata_toregion(rdata
, ®ion
);
70 return (inet_totext(AF_INET6
, ®ion
, target
));
73 static inline isc_result_t
74 fromwire_in_aaaa(ARGS_FROMWIRE
) {
79 REQUIRE(rdclass
== 1);
86 isc_buffer_activeregion(source
, &sregion
);
87 isc_buffer_availableregion(target
, &tregion
);
88 if (sregion
.length
< 16)
89 return (ISC_R_UNEXPECTEDEND
);
90 if (tregion
.length
< 16)
91 return (ISC_R_NOSPACE
);
93 memcpy(tregion
.base
, sregion
.base
, 16);
94 isc_buffer_forward(source
, 16);
95 isc_buffer_add(target
, 16);
96 return (ISC_R_SUCCESS
);
99 static inline isc_result_t
100 towire_in_aaaa(ARGS_TOWIRE
) {
105 REQUIRE(rdata
->type
== 28);
106 REQUIRE(rdata
->rdclass
== 1);
107 REQUIRE(rdata
->length
== 16);
109 isc_buffer_availableregion(target
, ®ion
);
110 if (region
.length
< rdata
->length
)
111 return (ISC_R_NOSPACE
);
112 memcpy(region
.base
, rdata
->data
, rdata
->length
);
113 isc_buffer_add(target
, 16);
114 return (ISC_R_SUCCESS
);
118 compare_in_aaaa(ARGS_COMPARE
) {
122 REQUIRE(rdata1
->type
== rdata2
->type
);
123 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
124 REQUIRE(rdata1
->type
== 28);
125 REQUIRE(rdata1
->rdclass
== 1);
126 REQUIRE(rdata1
->length
== 16);
127 REQUIRE(rdata2
->length
== 16);
129 dns_rdata_toregion(rdata1
, &r1
);
130 dns_rdata_toregion(rdata2
, &r2
);
131 return (compare_region(&r1
, &r2
));
134 static inline isc_result_t
135 fromstruct_in_aaaa(ARGS_FROMSTRUCT
) {
136 dns_rdata_in_aaaa_t
*aaaa
= source
;
139 REQUIRE(rdclass
== 1);
140 REQUIRE(source
!= NULL
);
141 REQUIRE(aaaa
->common
.rdtype
== type
);
142 REQUIRE(aaaa
->common
.rdclass
== rdclass
);
147 return (mem_tobuffer(target
, aaaa
->in6_addr
.s6_addr
, 16));
150 static inline isc_result_t
151 tostruct_in_aaaa(ARGS_TOSTRUCT
) {
152 dns_rdata_in_aaaa_t
*aaaa
= target
;
155 REQUIRE(rdata
->type
== 28);
156 REQUIRE(rdata
->rdclass
== 1);
157 REQUIRE(target
!= NULL
);
158 REQUIRE(rdata
->length
== 16);
162 aaaa
->common
.rdclass
= rdata
->rdclass
;
163 aaaa
->common
.rdtype
= rdata
->type
;
164 ISC_LINK_INIT(&aaaa
->common
, link
);
166 dns_rdata_toregion(rdata
, &r
);
167 INSIST(r
.length
== 16);
168 memcpy(aaaa
->in6_addr
.s6_addr
, r
.base
, 16);
170 return (ISC_R_SUCCESS
);
174 freestruct_in_aaaa(ARGS_FREESTRUCT
) {
175 dns_rdata_in_aaaa_t
*aaaa
= source
;
177 REQUIRE(source
!= NULL
);
178 REQUIRE(aaaa
->common
.rdclass
== 1);
179 REQUIRE(aaaa
->common
.rdtype
== 28);
184 static inline isc_result_t
185 additionaldata_in_aaaa(ARGS_ADDLDATA
) {
186 REQUIRE(rdata
->type
== 28);
187 REQUIRE(rdata
->rdclass
== 1);
193 return (ISC_R_SUCCESS
);
196 static inline isc_result_t
197 digest_in_aaaa(ARGS_DIGEST
) {
200 REQUIRE(rdata
->type
== 28);
201 REQUIRE(rdata
->rdclass
== 1);
203 dns_rdata_toregion(rdata
, &r
);
205 return ((digest
)(arg
, &r
));
208 #endif /* RDATA_IN_1_AAAA_28_C */