2 * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-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.31 2007/06/19 23:47:17 tbox Exp $ */
20 /* reviewed: Thu Mar 16 15:58:36 PST 2000 by brister */
22 #ifndef RDATA_HS_4_A_1_C
23 #define RDATA_HS_4_A_1_C
27 #define RRTYPE_A_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_hs_a(ARGS_FROMTEXT) {
36 REQUIRE(rdclass == 4);
43 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
46 if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1)
47 RETTOK(DNS_R_BADDOTTEDQUAD);
48 isc_buffer_availableregion(target, ®ion);
49 if (region.length < 4)
50 return (ISC_R_NOSPACE);
51 memcpy(region.base, &addr, 4);
52 isc_buffer_add(target, 4);
53 return (ISC_R_SUCCESS);
56 static inline isc_result_t
57 totext_hs_a(ARGS_TOTEXT) {
60 REQUIRE(rdata->type == 1);
61 REQUIRE(rdata->rdclass == 4);
62 REQUIRE(rdata->length == 4);
66 dns_rdata_toregion(rdata, ®ion);
67 return (inet_totext(AF_INET, ®ion, target));
70 static inline isc_result_t
71 fromwire_hs_a(ARGS_FROMWIRE) {
76 REQUIRE(rdclass == 4);
83 isc_buffer_activeregion(source, &sregion);
84 isc_buffer_availableregion(target, &tregion);
85 if (sregion.length < 4)
86 return (ISC_R_UNEXPECTEDEND);
87 if (tregion.length < 4)
88 return (ISC_R_NOSPACE);
90 memcpy(tregion.base, sregion.base, 4);
91 isc_buffer_forward(source, 4);
92 isc_buffer_add(target, 4);
93 return (ISC_R_SUCCESS);
96 static inline isc_result_t
97 towire_hs_a(ARGS_TOWIRE) {
100 REQUIRE(rdata->type == 1);
101 REQUIRE(rdata->rdclass == 4);
102 REQUIRE(rdata->length == 4);
106 isc_buffer_availableregion(target, ®ion);
107 if (region.length < rdata->length)
108 return (ISC_R_NOSPACE);
109 memcpy(region.base, rdata->data, rdata->length);
110 isc_buffer_add(target, 4);
111 return (ISC_R_SUCCESS);
115 compare_hs_a(ARGS_COMPARE) {
118 REQUIRE(rdata1->type == rdata2->type);
119 REQUIRE(rdata1->rdclass == rdata2->rdclass);
120 REQUIRE(rdata1->type == 1);
121 REQUIRE(rdata1->rdclass == 4);
122 REQUIRE(rdata1->length == 4);
123 REQUIRE(rdata2->length == 4);
125 order = memcmp(rdata1->data, rdata2->data, 4);
127 order = (order < 0) ? -1 : 1;
132 static inline isc_result_t
133 fromstruct_hs_a(ARGS_FROMSTRUCT) {
134 dns_rdata_hs_a_t *a = source;
138 REQUIRE(rdclass == 4);
139 REQUIRE(source != NULL);
140 REQUIRE(a->common.rdtype == type);
141 REQUIRE(a->common.rdclass == rdclass);
146 n = ntohl(a->in_addr.s_addr);
148 return (uint32_tobuffer(n, target));
151 static inline isc_result_t
152 tostruct_hs_a(ARGS_TOSTRUCT) {
153 dns_rdata_hs_a_t *a = target;
157 REQUIRE(rdata->type == 1);
158 REQUIRE(rdata->rdclass == 4);
159 REQUIRE(rdata->length == 4);
163 a->common.rdclass = rdata->rdclass;
164 a->common.rdtype = rdata->type;
165 ISC_LINK_INIT(&a->common, link);
167 dns_rdata_toregion(rdata, ®ion);
168 n = uint32_fromregion(®ion);
169 a->in_addr.s_addr = htonl(n);
171 return (ISC_R_SUCCESS);
175 freestruct_hs_a(ARGS_FREESTRUCT) {
178 REQUIRE(source != NULL);
181 static inline isc_result_t
182 additionaldata_hs_a(ARGS_ADDLDATA) {
183 REQUIRE(rdata->type == 1);
184 REQUIRE(rdata->rdclass == 4);
190 return (ISC_R_SUCCESS);
193 static inline isc_result_t
194 digest_hs_a(ARGS_DIGEST) {
197 REQUIRE(rdata->type == 1);
198 REQUIRE(rdata->rdclass == 4);
200 dns_rdata_toregion(rdata, &r);
202 return ((digest)(arg, &r));
205 static inline isc_boolean_t
206 checkowner_hs_a(ARGS_CHECKOWNER) {
209 REQUIRE(rdclass == 4);
219 static inline isc_boolean_t
220 checknames_hs_a(ARGS_CHECKNAMES) {
222 REQUIRE(rdata->type == 1);
223 REQUIRE(rdata->rdclass == 4);
232 #endif /* RDATA_HS_4_A_1_C */