Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / l32_105.c
blobb11719624a21ff1a3d774e2263856b703f4bee49
1 /* $NetBSD: l32_105.c,v 1.1.1.4 2014/12/10 03:34:42 christos Exp $ */
3 /*
4 * Copyright (C) 2013, 2014 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 #ifndef RDATA_GENERIC_L32_105_C
20 #define RDATA_GENERIC_L32_105_C
22 #include <string.h>
24 #include <isc/net.h>
26 #define RRTYPE_L32_ATTRIBUTES (0)
28 static inline isc_result_t
29 fromtext_l32(ARGS_FROMTEXT) {
30 isc_token_t token;
31 struct in_addr addr;
32 isc_region_t region;
34 REQUIRE(type == 105);
36 UNUSED(type);
37 UNUSED(rdclass);
38 UNUSED(origin);
39 UNUSED(options);
40 UNUSED(callbacks);
42 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
43 ISC_FALSE));
44 if (token.value.as_ulong > 0xffffU)
45 RETTOK(ISC_R_RANGE);
46 RETERR(uint16_tobuffer(token.value.as_ulong, target));
48 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
49 ISC_FALSE));
51 if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1)
52 RETTOK(DNS_R_BADDOTTEDQUAD);
53 isc_buffer_availableregion(target, &region);
54 if (region.length < 4)
55 return (ISC_R_NOSPACE);
56 memmove(region.base, &addr, 4);
57 isc_buffer_add(target, 4);
58 return (ISC_R_SUCCESS);
61 static inline isc_result_t
62 totext_l32(ARGS_TOTEXT) {
63 isc_region_t region;
64 char buf[sizeof("65000")];
65 unsigned short num;
67 REQUIRE(rdata->type == 105);
68 REQUIRE(rdata->length == 6);
70 UNUSED(tctx);
72 dns_rdata_toregion(rdata, &region);
73 num = uint16_fromregion(&region);
74 isc_region_consume(&region, 2);
75 sprintf(buf, "%u", num);
76 RETERR(str_totext(buf, target));
78 RETERR(str_totext(" ", target));
80 return (inet_totext(AF_INET, &region, target));
83 static inline isc_result_t
84 fromwire_l32(ARGS_FROMWIRE) {
85 isc_region_t sregion;
87 REQUIRE(type == 105);
89 UNUSED(type);
90 UNUSED(options);
91 UNUSED(rdclass);
92 UNUSED(dctx);
94 isc_buffer_activeregion(source, &sregion);
95 if (sregion.length != 6)
96 return (DNS_R_FORMERR);
97 isc_buffer_forward(source, sregion.length);
98 return (mem_tobuffer(target, sregion.base, sregion.length));
101 static inline isc_result_t
102 towire_l32(ARGS_TOWIRE) {
104 REQUIRE(rdata->type == 105);
105 REQUIRE(rdata->length == 6);
107 UNUSED(cctx);
109 return (mem_tobuffer(target, rdata->data, rdata->length));
112 static inline int
113 compare_l32(ARGS_COMPARE) {
114 isc_region_t region1;
115 isc_region_t region2;
117 REQUIRE(rdata1->type == rdata2->type);
118 REQUIRE(rdata1->rdclass == rdata2->rdclass);
119 REQUIRE(rdata1->type == 105);
120 REQUIRE(rdata1->length == 6);
121 REQUIRE(rdata2->length == 6);
123 dns_rdata_toregion(rdata1, &region1);
124 dns_rdata_toregion(rdata2, &region2);
125 return (isc_region_compare(&region1, &region2));
128 static inline isc_result_t
129 fromstruct_l32(ARGS_FROMSTRUCT) {
130 dns_rdata_l32_t *l32 = source;
131 isc_uint32_t n;
133 REQUIRE(type == 105);
134 REQUIRE(source != NULL);
135 REQUIRE(l32->common.rdtype == type);
136 REQUIRE(l32->common.rdclass == rdclass);
138 UNUSED(type);
139 UNUSED(rdclass);
141 RETERR(uint16_tobuffer(l32->pref, target));
142 n = ntohl(l32->l32.s_addr);
143 return (uint32_tobuffer(n, target));
146 static inline isc_result_t
147 tostruct_l32(ARGS_TOSTRUCT) {
148 isc_region_t region;
149 dns_rdata_l32_t *l32 = target;
150 isc_uint32_t n;
152 REQUIRE(rdata->type == 105);
153 REQUIRE(target != NULL);
154 REQUIRE(rdata->length == 6);
156 UNUSED(mctx);
158 l32->common.rdclass = rdata->rdclass;
159 l32->common.rdtype = rdata->type;
160 ISC_LINK_INIT(&l32->common, link);
162 dns_rdata_toregion(rdata, &region);
163 l32->pref = uint16_fromregion(&region);
164 n = uint32_fromregion(&region);
165 l32->l32.s_addr = htonl(n);
166 return (ISC_R_SUCCESS);
169 static inline void
170 freestruct_l32(ARGS_FREESTRUCT) {
171 dns_rdata_l32_t *l32 = source;
173 REQUIRE(source != NULL);
174 REQUIRE(l32->common.rdtype == 105);
176 return;
179 static inline isc_result_t
180 additionaldata_l32(ARGS_ADDLDATA) {
182 REQUIRE(rdata->type == 105);
183 REQUIRE(rdata->length == 6);
185 UNUSED(rdata);
186 UNUSED(add);
187 UNUSED(arg);
189 return (ISC_R_SUCCESS);
192 static inline isc_result_t
193 digest_l32(ARGS_DIGEST) {
194 isc_region_t r;
196 REQUIRE(rdata->type == 105);
197 REQUIRE(rdata->length == 6);
199 dns_rdata_toregion(rdata, &r);
201 return ((digest)(arg, &r));
204 static inline isc_boolean_t
205 checkowner_l32(ARGS_CHECKOWNER) {
207 REQUIRE(type == 105);
209 UNUSED(name);
210 UNUSED(type);
211 UNUSED(rdclass);
212 UNUSED(wildcard);
214 return (ISC_TRUE);
217 static inline isc_boolean_t
218 checknames_l32(ARGS_CHECKNAMES) {
220 REQUIRE(rdata->type == 105);
221 REQUIRE(rdata->length == 6);
223 UNUSED(rdata);
224 UNUSED(owner);
225 UNUSED(bad);
227 return (ISC_TRUE);
230 static inline int
231 casecompare_l32(ARGS_COMPARE) {
232 return (compare_l32(rdata1, rdata2));
235 #endif /* RDATA_GENERIC_L32_105_C */