Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / in_1 / a_1.c
blob6708fae4bd695a83c06999dbc5bd2b9d23ad4ddf
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) 1998-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.55 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */
24 #ifndef RDATA_IN_1_A_1_C
25 #define RDATA_IN_1_A_1_C
27 #include <string.h>
29 #include <isc/net.h>
31 #define RRTYPE_A_ATTRIBUTES (0)
33 static inline isc_result_t
34 fromtext_in_a(ARGS_FROMTEXT) {
35 isc_token_t token;
36 struct in_addr addr;
37 isc_region_t region;
39 REQUIRE(type == 1);
40 REQUIRE(rdclass == 1);
42 UNUSED(type);
43 UNUSED(origin);
44 UNUSED(options);
45 UNUSED(rdclass);
47 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
48 ISC_FALSE));
50 if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1)
51 RETTOK(DNS_R_BADDOTTEDQUAD);
52 isc_buffer_availableregion(target, &region);
53 if (region.length < 4)
54 return (ISC_R_NOSPACE);
55 memmove(region.base, &addr, 4);
56 isc_buffer_add(target, 4);
57 return (ISC_R_SUCCESS);
60 static inline isc_result_t
61 totext_in_a(ARGS_TOTEXT) {
62 isc_region_t region;
64 REQUIRE(rdata->type == 1);
65 REQUIRE(rdata->rdclass == 1);
66 REQUIRE(rdata->length == 4);
68 UNUSED(tctx);
70 dns_rdata_toregion(rdata, &region);
71 return (inet_totext(AF_INET, &region, target));
74 static inline isc_result_t
75 fromwire_in_a(ARGS_FROMWIRE) {
76 isc_region_t sregion;
77 isc_region_t tregion;
79 REQUIRE(type == 1);
80 REQUIRE(rdclass == 1);
82 UNUSED(type);
83 UNUSED(dctx);
84 UNUSED(options);
85 UNUSED(rdclass);
87 isc_buffer_activeregion(source, &sregion);
88 isc_buffer_availableregion(target, &tregion);
89 if (sregion.length < 4)
90 return (ISC_R_UNEXPECTEDEND);
91 if (tregion.length < 4)
92 return (ISC_R_NOSPACE);
94 memmove(tregion.base, sregion.base, 4);
95 isc_buffer_forward(source, 4);
96 isc_buffer_add(target, 4);
97 return (ISC_R_SUCCESS);
100 static inline isc_result_t
101 towire_in_a(ARGS_TOWIRE) {
102 isc_region_t region;
104 REQUIRE(rdata->type == 1);
105 REQUIRE(rdata->rdclass == 1);
106 REQUIRE(rdata->length == 4);
108 UNUSED(cctx);
110 isc_buffer_availableregion(target, &region);
111 if (region.length < rdata->length)
112 return (ISC_R_NOSPACE);
113 memmove(region.base, rdata->data, rdata->length);
114 isc_buffer_add(target, 4);
115 return (ISC_R_SUCCESS);
118 static inline int
119 compare_in_a(ARGS_COMPARE) {
120 isc_region_t r1;
121 isc_region_t r2;
123 REQUIRE(rdata1->type == rdata2->type);
124 REQUIRE(rdata1->rdclass == rdata2->rdclass);
125 REQUIRE(rdata1->type == 1);
126 REQUIRE(rdata1->rdclass == 1);
127 REQUIRE(rdata1->length == 4);
128 REQUIRE(rdata2->length == 4);
130 dns_rdata_toregion(rdata1, &r1);
131 dns_rdata_toregion(rdata2, &r2);
132 return (isc_region_compare(&r1, &r2));
135 static inline isc_result_t
136 fromstruct_in_a(ARGS_FROMSTRUCT) {
137 dns_rdata_in_a_t *a = source;
138 isc_uint32_t n;
140 REQUIRE(type == 1);
141 REQUIRE(rdclass == 1);
142 REQUIRE(source != NULL);
143 REQUIRE(a->common.rdtype == type);
144 REQUIRE(a->common.rdclass == rdclass);
146 UNUSED(type);
147 UNUSED(rdclass);
149 n = ntohl(a->in_addr.s_addr);
151 return (uint32_tobuffer(n, target));
155 static inline isc_result_t
156 tostruct_in_a(ARGS_TOSTRUCT) {
157 dns_rdata_in_a_t *a = target;
158 isc_uint32_t n;
159 isc_region_t region;
161 REQUIRE(rdata->type == 1);
162 REQUIRE(rdata->rdclass == 1);
163 REQUIRE(rdata->length == 4);
165 UNUSED(mctx);
167 a->common.rdclass = rdata->rdclass;
168 a->common.rdtype = rdata->type;
169 ISC_LINK_INIT(&a->common, link);
171 dns_rdata_toregion(rdata, &region);
172 n = uint32_fromregion(&region);
173 a->in_addr.s_addr = htonl(n);
175 return (ISC_R_SUCCESS);
178 static inline void
179 freestruct_in_a(ARGS_FREESTRUCT) {
180 dns_rdata_in_a_t *a = source;
182 REQUIRE(source != NULL);
183 REQUIRE(a->common.rdtype == 1);
184 REQUIRE(a->common.rdclass == 1);
186 UNUSED(a);
189 static inline isc_result_t
190 additionaldata_in_a(ARGS_ADDLDATA) {
191 REQUIRE(rdata->type == 1);
192 REQUIRE(rdata->rdclass == 1);
194 UNUSED(rdata);
195 UNUSED(add);
196 UNUSED(arg);
198 return (ISC_R_SUCCESS);
201 static inline isc_result_t
202 digest_in_a(ARGS_DIGEST) {
203 isc_region_t r;
205 REQUIRE(rdata->type == 1);
206 REQUIRE(rdata->rdclass == 1);
208 dns_rdata_toregion(rdata, &r);
210 return ((digest)(arg, &r));
213 static inline isc_boolean_t
214 checkowner_in_a(ARGS_CHECKOWNER) {
216 REQUIRE(type == 1);
217 REQUIRE(rdclass == 1);
219 UNUSED(type);
220 UNUSED(rdclass);
222 return (dns_name_ishostname(name, wildcard));
225 static inline isc_boolean_t
226 checknames_in_a(ARGS_CHECKNAMES) {
228 REQUIRE(rdata->type == 1);
229 REQUIRE(rdata->rdclass == 1);
231 UNUSED(rdata);
232 UNUSED(owner);
233 UNUSED(bad);
235 return (ISC_TRUE);
238 static inline int
239 casecompare_in_a(ARGS_COMPARE) {
240 return (compare_in_a(rdata1, rdata2));
243 #endif /* RDATA_IN_1_A_1_C */