Merge from vendor branch TCPDUMP:
[dragonfly.git] / contrib / bind-9.3 / lib / dns / rdata / hs_4 / a_1.c
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2002  Internet Software Consortium.
4  *
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.
8  *
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.
16  */
17
18 /* $Id: a_1.c,v 1.25.12.4 2004/03/08 09:04:43 marka Exp $ */
19
20 /* reviewed: Thu Mar 16 15:58:36 PST 2000 by brister */
21
22 #ifndef RDATA_HS_4_A_1_C
23 #define RDATA_HS_4_A_1_C
24
25 #include <isc/net.h>
26
27 #define RRTYPE_A_ATTRIBUTES (0)
28
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;
34
35         REQUIRE(type == 1);
36         REQUIRE(rdclass == 4);
37
38         UNUSED(type);
39         UNUSED(origin);
40         UNUSED(options);
41         UNUSED(rdclass);
42
43         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
44                                       ISC_FALSE));
45
46         if (getquad(DNS_AS_STR(token), &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);
54 }
55
56 static inline isc_result_t
57 totext_hs_a(ARGS_TOTEXT) {
58         isc_region_t region;
59
60         REQUIRE(rdata->type == 1);
61         REQUIRE(rdata->rdclass == 4);
62         REQUIRE(rdata->length == 4);
63
64         UNUSED(tctx);
65
66         dns_rdata_toregion(rdata, &region);
67         return (inet_totext(AF_INET, &region, target));
68 }
69
70 static inline isc_result_t
71 fromwire_hs_a(ARGS_FROMWIRE) {
72         isc_region_t sregion;
73         isc_region_t tregion;
74
75         REQUIRE(type == 1);
76         REQUIRE(rdclass == 4);
77
78         UNUSED(type);
79         UNUSED(dctx);
80         UNUSED(options);
81         UNUSED(rdclass);
82
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);
89
90         memcpy(tregion.base, sregion.base, 4);
91         isc_buffer_forward(source, 4);
92         isc_buffer_add(target, 4);
93         return (ISC_R_SUCCESS);
94 }
95
96 static inline isc_result_t
97 towire_hs_a(ARGS_TOWIRE) {
98         isc_region_t region;
99
100         REQUIRE(rdata->type == 1);
101         REQUIRE(rdata->rdclass == 4);
102         REQUIRE(rdata->length == 4);
103
104         UNUSED(cctx);
105
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);
112 }
113
114 static inline int
115 compare_hs_a(ARGS_COMPARE) {
116         int order;
117
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);
124
125         order = memcmp(rdata1->data, rdata2->data, 4);
126         if (order != 0)
127                 order = (order < 0) ? -1 : 1;
128
129         return (order);
130 }
131
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;
136
137         REQUIRE(type == 1);
138         REQUIRE(rdclass == 4);
139         REQUIRE(source != NULL);
140         REQUIRE(a->common.rdtype == type);
141         REQUIRE(a->common.rdclass == rdclass);
142
143         UNUSED(type);
144         UNUSED(rdclass);
145
146         n = ntohl(a->in_addr.s_addr);
147
148         return (uint32_tobuffer(n, target));
149 }
150
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;
156
157         REQUIRE(rdata->type == 1);
158         REQUIRE(rdata->rdclass == 4);
159         REQUIRE(rdata->length == 4);
160
161         UNUSED(mctx);
162
163         a->common.rdclass = rdata->rdclass;
164         a->common.rdtype = rdata->type;
165         ISC_LINK_INIT(&a->common, link);
166
167         dns_rdata_toregion(rdata, &region);
168         n = uint32_fromregion(&region);
169         a->in_addr.s_addr = htonl(n);
170
171         return (ISC_R_SUCCESS);
172 }
173
174 static inline void
175 freestruct_hs_a(ARGS_FREESTRUCT) {
176         UNUSED(source);
177
178         REQUIRE(source != NULL);
179 }
180
181 static inline isc_result_t
182 additionaldata_hs_a(ARGS_ADDLDATA) {
183         REQUIRE(rdata->type == 1);
184         REQUIRE(rdata->rdclass == 4);
185
186         UNUSED(rdata);
187         UNUSED(add);
188         UNUSED(arg);
189
190         return (ISC_R_SUCCESS);
191 }
192
193 static inline isc_result_t
194 digest_hs_a(ARGS_DIGEST) {
195         isc_region_t r;
196
197         REQUIRE(rdata->type == 1);
198         REQUIRE(rdata->rdclass == 4);
199
200         dns_rdata_toregion(rdata, &r);
201
202         return ((digest)(arg, &r));
203 }
204
205 static inline isc_boolean_t
206 checkowner_hs_a(ARGS_CHECKOWNER) {
207
208         REQUIRE(type == 1);
209         REQUIRE(rdclass == 4);
210
211         UNUSED(name);
212         UNUSED(type);
213         UNUSED(rdclass);
214         UNUSED(wildcard);
215
216         return (ISC_TRUE);
217 }
218
219 static inline isc_boolean_t
220 checknames_hs_a(ARGS_CHECKNAMES) {
221
222         REQUIRE(rdata->type == 1);
223         REQUIRE(rdata->rdclass == 4);
224
225         UNUSED(rdata);
226         UNUSED(owner);
227         UNUSED(bad);
228
229         return (ISC_TRUE);
230 }
231
232 #endif  /* RDATA_HS_4_A_1_C */