Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / dns / rdata / in_1 / aaaa_28.c
blob02bac1fbdde0e8b296dfaae49d10f60a2b03ea18
1 /*
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 */
22 /* RFC 1886 */
24 #ifndef RDATA_IN_1_AAAA_28_C
25 #define RDATA_IN_1_AAAA_28_C
27 #include <isc/net.h>
29 #define RRTYPE_AAAA_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_in_aaaa(ARGS_FROMTEXT) {
33 isc_token_t token;
34 unsigned char addr[16];
35 isc_region_t region;
37 REQUIRE(type == 28);
38 REQUIRE(rdclass == 1);
40 UNUSED(type);
41 UNUSED(origin);
42 UNUSED(downcase);
43 UNUSED(rdclass);
44 UNUSED(callbacks);
46 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
47 ISC_FALSE));
49 if (inet_pton(AF_INET6, token.value.as_pointer, addr) != 1)
50 RETTOK(DNS_R_BADAAAA);
51 isc_buffer_availableregion(target, &region);
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) {
61 isc_region_t region;
63 UNUSED(tctx);
65 REQUIRE(rdata->type == 28);
66 REQUIRE(rdata->rdclass == 1);
67 REQUIRE(rdata->length == 16);
69 dns_rdata_toregion(rdata, &region);
70 return (inet_totext(AF_INET6, &region, target));
73 static inline isc_result_t
74 fromwire_in_aaaa(ARGS_FROMWIRE) {
75 isc_region_t sregion;
76 isc_region_t tregion;
78 REQUIRE(type == 28);
79 REQUIRE(rdclass == 1);
81 UNUSED(type);
82 UNUSED(dctx);
83 UNUSED(downcase);
84 UNUSED(rdclass);
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) {
101 isc_region_t region;
103 UNUSED(cctx);
105 REQUIRE(rdata->type == 28);
106 REQUIRE(rdata->rdclass == 1);
107 REQUIRE(rdata->length == 16);
109 isc_buffer_availableregion(target, &region);
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);
117 static inline int
118 compare_in_aaaa(ARGS_COMPARE) {
119 isc_region_t r1;
120 isc_region_t r2;
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;
138 REQUIRE(type == 28);
139 REQUIRE(rdclass == 1);
140 REQUIRE(source != NULL);
141 REQUIRE(aaaa->common.rdtype == type);
142 REQUIRE(aaaa->common.rdclass == rdclass);
144 UNUSED(type);
145 UNUSED(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;
153 isc_region_t r;
155 REQUIRE(rdata->type == 28);
156 REQUIRE(rdata->rdclass == 1);
157 REQUIRE(target != NULL);
158 REQUIRE(rdata->length == 16);
160 UNUSED(mctx);
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);
173 static inline void
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);
181 UNUSED(aaaa);
184 static inline isc_result_t
185 additionaldata_in_aaaa(ARGS_ADDLDATA) {
186 REQUIRE(rdata->type == 28);
187 REQUIRE(rdata->rdclass == 1);
189 UNUSED(rdata);
190 UNUSED(add);
191 UNUSED(arg);
193 return (ISC_R_SUCCESS);
196 static inline isc_result_t
197 digest_in_aaaa(ARGS_DIGEST) {
198 isc_region_t r;
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 */