Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / hs_4 / a_1.c
blobfef587baf8c348dc5a286589d5c2507dc8c3ea1e
1 /* $NetBSD: a_1.c,v 1.5 2014/12/10 04:37:59 christos Exp $ */
3 /*
4 * Copyright (C) 2004, 2007, 2009, 2014 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2002 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: a_1.c,v 1.33 2009/12/04 22:06:37 tbox Exp */
22 /* reviewed: Thu Mar 16 15:58:36 PST 2000 by brister */
24 #ifndef RDATA_HS_4_A_1_C
25 #define RDATA_HS_4_A_1_C
27 #include <isc/net.h>
29 #define RRTYPE_A_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_hs_a(ARGS_FROMTEXT) {
33 isc_token_t token;
34 struct in_addr addr;
35 isc_region_t region;
37 REQUIRE(type == 1);
38 REQUIRE(rdclass == 4);
40 UNUSED(type);
41 UNUSED(origin);
42 UNUSED(options);
43 UNUSED(rdclass);
45 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
46 ISC_FALSE));
48 if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1)
49 RETTOK(DNS_R_BADDOTTEDQUAD);
50 isc_buffer_availableregion(target, &region);
51 if (region.length < 4)
52 return (ISC_R_NOSPACE);
53 memmove(region.base, &addr, 4);
54 isc_buffer_add(target, 4);
55 return (ISC_R_SUCCESS);
58 static inline isc_result_t
59 totext_hs_a(ARGS_TOTEXT) {
60 isc_region_t region;
62 REQUIRE(rdata->type == 1);
63 REQUIRE(rdata->rdclass == 4);
64 REQUIRE(rdata->length == 4);
66 UNUSED(tctx);
68 dns_rdata_toregion(rdata, &region);
69 return (inet_totext(AF_INET, &region, target));
72 static inline isc_result_t
73 fromwire_hs_a(ARGS_FROMWIRE) {
74 isc_region_t sregion;
75 isc_region_t tregion;
77 REQUIRE(type == 1);
78 REQUIRE(rdclass == 4);
80 UNUSED(type);
81 UNUSED(dctx);
82 UNUSED(options);
83 UNUSED(rdclass);
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 memmove(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_hs_a(ARGS_TOWIRE) {
100 isc_region_t region;
102 REQUIRE(rdata->type == 1);
103 REQUIRE(rdata->rdclass == 4);
104 REQUIRE(rdata->length == 4);
106 UNUSED(cctx);
108 isc_buffer_availableregion(target, &region);
109 if (region.length < rdata->length)
110 return (ISC_R_NOSPACE);
111 memmove(region.base, rdata->data, rdata->length);
112 isc_buffer_add(target, 4);
113 return (ISC_R_SUCCESS);
116 static inline int
117 compare_hs_a(ARGS_COMPARE) {
118 int order;
120 REQUIRE(rdata1->type == rdata2->type);
121 REQUIRE(rdata1->rdclass == rdata2->rdclass);
122 REQUIRE(rdata1->type == 1);
123 REQUIRE(rdata1->rdclass == 4);
124 REQUIRE(rdata1->length == 4);
125 REQUIRE(rdata2->length == 4);
127 order = memcmp(rdata1->data, rdata2->data, 4);
128 if (order != 0)
129 order = (order < 0) ? -1 : 1;
131 return (order);
134 static inline isc_result_t
135 fromstruct_hs_a(ARGS_FROMSTRUCT) {
136 dns_rdata_hs_a_t *a = source;
137 isc_uint32_t n;
139 REQUIRE(type == 1);
140 REQUIRE(rdclass == 4);
141 REQUIRE(source != NULL);
142 REQUIRE(a->common.rdtype == type);
143 REQUIRE(a->common.rdclass == rdclass);
145 UNUSED(type);
146 UNUSED(rdclass);
148 n = ntohl(a->in_addr.s_addr);
150 return (uint32_tobuffer(n, target));
153 static inline isc_result_t
154 tostruct_hs_a(ARGS_TOSTRUCT) {
155 dns_rdata_hs_a_t *a = target;
156 isc_uint32_t n;
157 isc_region_t region;
159 REQUIRE(rdata->type == 1);
160 REQUIRE(rdata->rdclass == 4);
161 REQUIRE(rdata->length == 4);
163 UNUSED(mctx);
165 a->common.rdclass = rdata->rdclass;
166 a->common.rdtype = rdata->type;
167 ISC_LINK_INIT(&a->common, link);
169 dns_rdata_toregion(rdata, &region);
170 n = uint32_fromregion(&region);
171 a->in_addr.s_addr = htonl(n);
173 return (ISC_R_SUCCESS);
176 static inline void
177 freestruct_hs_a(ARGS_FREESTRUCT) {
178 UNUSED(source);
180 REQUIRE(source != NULL);
183 static inline isc_result_t
184 additionaldata_hs_a(ARGS_ADDLDATA) {
185 REQUIRE(rdata->type == 1);
186 REQUIRE(rdata->rdclass == 4);
188 UNUSED(rdata);
189 UNUSED(add);
190 UNUSED(arg);
192 return (ISC_R_SUCCESS);
195 static inline isc_result_t
196 digest_hs_a(ARGS_DIGEST) {
197 isc_region_t r;
199 REQUIRE(rdata->type == 1);
200 REQUIRE(rdata->rdclass == 4);
202 dns_rdata_toregion(rdata, &r);
204 return ((digest)(arg, &r));
207 static inline isc_boolean_t
208 checkowner_hs_a(ARGS_CHECKOWNER) {
210 REQUIRE(type == 1);
211 REQUIRE(rdclass == 4);
213 UNUSED(name);
214 UNUSED(type);
215 UNUSED(rdclass);
216 UNUSED(wildcard);
218 return (ISC_TRUE);
221 static inline isc_boolean_t
222 checknames_hs_a(ARGS_CHECKNAMES) {
224 REQUIRE(rdata->type == 1);
225 REQUIRE(rdata->rdclass == 4);
227 UNUSED(rdata);
228 UNUSED(owner);
229 UNUSED(bad);
231 return (ISC_TRUE);
234 static inline int
235 casecompare_hs_a(ARGS_COMPARE) {
236 return (compare_hs_a(rdata1, rdata2));
239 #endif /* RDATA_HS_4_A_1_C */