Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / dns / rdata / hs_4 / a_1.c
blob7a1ddd248da1dc0cac051caa09b7ce8f13c1df27
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: a_1.c,v 1.25.2.1 2004/03/09 06:11:35 marka 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
25 #include <isc/net.h>
27 #define RRTYPE_A_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_hs_a(ARGS_FROMTEXT) {
31 isc_token_t token;
32 struct in_addr addr;
33 isc_region_t region;
35 REQUIRE(type == 1);
36 REQUIRE(rdclass == 4);
38 UNUSED(type);
39 UNUSED(origin);
40 UNUSED(downcase);
41 UNUSED(rdclass);
43 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
44 ISC_FALSE));
46 if (getquad(token.value.as_pointer, &addr, lexer, callbacks) != 1)
47 RETTOK(DNS_R_BADDOTTEDQUAD);
48 isc_buffer_availableregion(target, &region);
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) {
58 isc_region_t region;
60 REQUIRE(rdata->type == 1);
61 REQUIRE(rdata->rdclass == 4);
62 REQUIRE(rdata->length == 4);
64 UNUSED(tctx);
66 dns_rdata_toregion(rdata, &region);
67 return (inet_totext(AF_INET, &region, target));
70 static inline isc_result_t
71 fromwire_hs_a(ARGS_FROMWIRE) {
72 isc_region_t sregion;
73 isc_region_t tregion;
75 REQUIRE(type == 1);
76 REQUIRE(rdclass == 4);
78 UNUSED(type);
79 UNUSED(dctx);
80 UNUSED(downcase);
81 UNUSED(rdclass);
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) {
98 isc_region_t region;
100 REQUIRE(rdata->type == 1);
101 REQUIRE(rdata->rdclass == 4);
102 REQUIRE(rdata->length == 4);
104 UNUSED(cctx);
106 isc_buffer_availableregion(target, &region);
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);
114 static inline int
115 compare_hs_a(ARGS_COMPARE) {
116 int order;
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);
126 if (order != 0)
127 order = (order < 0) ? -1 : 1;
129 return (order);
132 static inline isc_result_t
133 fromstruct_hs_a(ARGS_FROMSTRUCT) {
134 dns_rdata_hs_a_t *a = source;
135 isc_uint32_t n;
137 REQUIRE(type == 1);
138 REQUIRE(rdclass == 4);
139 REQUIRE(source != NULL);
140 REQUIRE(a->common.rdtype == type);
141 REQUIRE(a->common.rdclass == rdclass);
143 UNUSED(type);
144 UNUSED(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;
154 isc_uint32_t n;
155 isc_region_t region;
157 REQUIRE(rdata->type == 1);
158 REQUIRE(rdata->rdclass == 4);
159 REQUIRE(rdata->length == 4);
161 UNUSED(mctx);
163 a->common.rdclass = rdata->rdclass;
164 a->common.rdtype = rdata->type;
165 ISC_LINK_INIT(&a->common, link);
167 dns_rdata_toregion(rdata, &region);
168 n = uint32_fromregion(&region);
169 a->in_addr.s_addr = htonl(n);
171 return (ISC_R_SUCCESS);
174 static inline void
175 freestruct_hs_a(ARGS_FREESTRUCT) {
176 UNUSED(source);
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);
186 UNUSED(rdata);
187 UNUSED(add);
188 UNUSED(arg);
190 return (ISC_R_SUCCESS);
193 static inline isc_result_t
194 digest_hs_a(ARGS_DIGEST) {
195 isc_region_t r;
197 REQUIRE(rdata->type == 1);
198 REQUIRE(rdata->rdclass == 4);
200 dns_rdata_toregion(rdata, &r);
202 return ((digest)(arg, &r));
205 #endif /* RDATA_HS_4_A_1_C */