2 * Copyright (C) 2004, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998-2002 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or 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: a_1.c,v 1.55 2009-12-04 22:06:37 tbox Exp $ */
20 /* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */
22 #ifndef RDATA_IN_1_A_1_C
23 #define RDATA_IN_1_A_1_C
29 #define RRTYPE_A_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_in_a(ARGS_FROMTEXT) {
38 REQUIRE(rdclass == 1);
45 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
48 if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1)
49 RETTOK(DNS_R_BADDOTTEDQUAD);
50 isc_buffer_availableregion(target, ®ion);
51 if (region.length < 4)
52 return (ISC_R_NOSPACE);
53 memcpy(region.base, &addr, 4);
54 isc_buffer_add(target, 4);
55 return (ISC_R_SUCCESS);
58 static inline isc_result_t
59 totext_in_a(ARGS_TOTEXT) {
62 REQUIRE(rdata->type == 1);
63 REQUIRE(rdata->rdclass == 1);
64 REQUIRE(rdata->length == 4);
68 dns_rdata_toregion(rdata, ®ion);
69 return (inet_totext(AF_INET, ®ion, target));
72 static inline isc_result_t
73 fromwire_in_a(ARGS_FROMWIRE) {
78 REQUIRE(rdclass == 1);
85 isc_buffer_activeregion(source, &sregion);
86 isc_buffer_availableregion(target, &tregion);
87 if (sregion.length < 4)
88 return (ISC_R_UNEXPECTEDEND);
89 if (tregion.length < 4)
90 return (ISC_R_NOSPACE);
92 memcpy(tregion.base, sregion.base, 4);
93 isc_buffer_forward(source, 4);
94 isc_buffer_add(target, 4);
95 return (ISC_R_SUCCESS);
98 static inline isc_result_t
99 towire_in_a(ARGS_TOWIRE) {
102 REQUIRE(rdata->type == 1);
103 REQUIRE(rdata->rdclass == 1);
104 REQUIRE(rdata->length == 4);
108 isc_buffer_availableregion(target, ®ion);
109 if (region.length < rdata->length)
110 return (ISC_R_NOSPACE);
111 memcpy(region.base, rdata->data, rdata->length);
112 isc_buffer_add(target, 4);
113 return (ISC_R_SUCCESS);
117 compare_in_a(ARGS_COMPARE) {
121 REQUIRE(rdata1->type == rdata2->type);
122 REQUIRE(rdata1->rdclass == rdata2->rdclass);
123 REQUIRE(rdata1->type == 1);
124 REQUIRE(rdata1->rdclass == 1);
125 REQUIRE(rdata1->length == 4);
126 REQUIRE(rdata2->length == 4);
128 dns_rdata_toregion(rdata1, &r1);
129 dns_rdata_toregion(rdata2, &r2);
130 return (isc_region_compare(&r1, &r2));
133 static inline isc_result_t
134 fromstruct_in_a(ARGS_FROMSTRUCT) {
135 dns_rdata_in_a_t *a = source;
139 REQUIRE(rdclass == 1);
140 REQUIRE(source != NULL);
141 REQUIRE(a->common.rdtype == type);
142 REQUIRE(a->common.rdclass == rdclass);
147 n = ntohl(a->in_addr.s_addr);
149 return (uint32_tobuffer(n, target));
153 static inline isc_result_t
154 tostruct_in_a(ARGS_TOSTRUCT) {
155 dns_rdata_in_a_t *a = target;
159 REQUIRE(rdata->type == 1);
160 REQUIRE(rdata->rdclass == 1);
161 REQUIRE(rdata->length == 4);
165 a->common.rdclass = rdata->rdclass;
166 a->common.rdtype = rdata->type;
167 ISC_LINK_INIT(&a->common, link);
169 dns_rdata_toregion(rdata, ®ion);
170 n = uint32_fromregion(®ion);
171 a->in_addr.s_addr = htonl(n);
173 return (ISC_R_SUCCESS);
177 freestruct_in_a(ARGS_FREESTRUCT) {
178 dns_rdata_in_a_t *a = source;
180 REQUIRE(source != NULL);
181 REQUIRE(a->common.rdtype == 1);
182 REQUIRE(a->common.rdclass == 1);
187 static inline isc_result_t
188 additionaldata_in_a(ARGS_ADDLDATA) {
189 REQUIRE(rdata->type == 1);
190 REQUIRE(rdata->rdclass == 1);
196 return (ISC_R_SUCCESS);
199 static inline isc_result_t
200 digest_in_a(ARGS_DIGEST) {
203 REQUIRE(rdata->type == 1);
204 REQUIRE(rdata->rdclass == 1);
206 dns_rdata_toregion(rdata, &r);
208 return ((digest)(arg, &r));
211 static inline isc_boolean_t
212 checkowner_in_a(ARGS_CHECKOWNER) {
215 REQUIRE(rdclass == 1);
220 return (dns_name_ishostname(name, wildcard));
223 static inline isc_boolean_t
224 checknames_in_a(ARGS_CHECKNAMES) {
226 REQUIRE(rdata->type == 1);
227 REQUIRE(rdata->rdclass == 1);
237 casecompare_in_a(ARGS_COMPARE) {
238 return (compare_in_a(rdata1, rdata2));
241 #endif /* RDATA_IN_1_A_1_C */