a_1.c 4.94 KB
Newer Older
1
/*
Bob Halley's avatar
Bob Halley committed
2
 * Copyright (C) 1998, 1999, 2000  Internet Software Consortium.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 * 
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

18
/* $Id: a_1.c,v 1.30 2000/04/28 01:24:13 gson Exp $ */
Brian Wellington's avatar
Brian Wellington committed
19
20

/* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */
Mark Andrews's avatar
Mark Andrews committed
21

22
23
#ifndef RDATA_IN_1_A_1_C
#define RDATA_IN_1_A_1_C
Mark Andrews's avatar
Mark Andrews committed
24

Michael Graff's avatar
Michael Graff committed
25
26
#include <string.h>

27
#include <isc/net.h>
28

29
30
#define RRTYPE_A_ATTRIBUTES (0)

31
static inline isc_result_t
32
fromtext_in_a(dns_rdataclass_t rdclass, dns_rdatatype_t type,
33
	      isc_lex_t *lexer, dns_name_t *origin,
Mark Andrews's avatar
Mark Andrews committed
34
35
	      isc_boolean_t downcase, isc_buffer_t *target)
{
36
37
38
39
	isc_token_t token;
	struct in_addr addr;
	isc_region_t region;

Brian Wellington's avatar
Brian Wellington committed
40
41
42
	UNUSED(origin);
	UNUSED(downcase);

Mark Andrews's avatar
Mark Andrews committed
43
	REQUIRE(type == 1);
44
	REQUIRE(rdclass == 1);
Mark Andrews's avatar
Mark Andrews committed
45

46
	RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
47

48
	if (inet_aton(token.value.as_pointer, &addr) != 1)
49
		return (DNS_R_BADDOTTEDQUAD);
50
	isc_buffer_availableregion(target, &region);
51
	if (region.length < 4)
52
		return (ISC_R_NOSPACE);
53
54
	memcpy(region.base, &addr, 4);
	isc_buffer_add(target, 4);
55
	return (ISC_R_SUCCESS);
56
57
}

58
static inline isc_result_t
59
60
61
totext_in_a(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, 
	    isc_buffer_t *target) 
{
62
63
	isc_region_t region;

Brian Wellington's avatar
Brian Wellington committed
64
65
	UNUSED(tctx);

Mark Andrews's avatar
Mark Andrews committed
66
	REQUIRE(rdata->type == 1);
67
	REQUIRE(rdata->rdclass == 1);
Mark Andrews's avatar
Mark Andrews committed
68
	REQUIRE(rdata->length == 4);
69

70
	isc_buffer_availableregion(target, &region);
71
	if (inet_ntop(AF_INET, rdata->data,
72
			  (char *)region.base, region.length) == NULL)
73
		return (ISC_R_NOSPACE);
74

75
	isc_buffer_add(target, strlen((char *)region.base));
76
	return (ISC_R_SUCCESS);
77
78
}

79
static inline isc_result_t
80
fromwire_in_a(dns_rdataclass_t rdclass, dns_rdatatype_t type,
81
	      isc_buffer_t *source, dns_decompress_t *dctx,
Mark Andrews's avatar
Mark Andrews committed
82
83
	      isc_boolean_t downcase, isc_buffer_t *target)
{
84
85
86
	isc_region_t sregion;
	isc_region_t tregion;

Brian Wellington's avatar
Brian Wellington committed
87
88
89
	UNUSED(dctx);
	UNUSED(downcase);

Mark Andrews's avatar
Mark Andrews committed
90
	REQUIRE(type == 1);
91
	REQUIRE(rdclass == 1);
92

93
94
	isc_buffer_activeregion(source, &sregion);
	isc_buffer_availableregion(target, &tregion);
Mark Andrews's avatar
Mark Andrews committed
95
	if (sregion.length < 4)
96
		return (ISC_R_UNEXPECTEDEND);
97
	if (tregion.length < 4)
98
		return (ISC_R_NOSPACE);
99
100
101
102

	memcpy(tregion.base, sregion.base, 4);
	isc_buffer_forward(source, 4);
	isc_buffer_add(target, 4);
103
	return (ISC_R_SUCCESS);
104
105
}

106
static inline isc_result_t
107
108
109
towire_in_a(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
	isc_region_t region;

Brian Wellington's avatar
Brian Wellington committed
110
111
	UNUSED(cctx);

Mark Andrews's avatar
Mark Andrews committed
112
	REQUIRE(rdata->type == 1);
113
	REQUIRE(rdata->rdclass == 1);
Mark Andrews's avatar
Mark Andrews committed
114

115
	isc_buffer_availableregion(target, &region);
116
	if (region.length < rdata->length)
117
		return (ISC_R_NOSPACE);
118
119
	memcpy(region.base, rdata->data, rdata->length);
	isc_buffer_add(target, 4);
120
	return (ISC_R_SUCCESS);
121
122
}

123
static inline int
124
compare_in_a(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
Brian Wellington's avatar
Brian Wellington committed
125
126
	isc_region_t r1;
	isc_region_t r2;
Brian Wellington's avatar
Brian Wellington committed
127

Mark Andrews's avatar
Mark Andrews committed
128
	REQUIRE(rdata1->type == rdata2->type);
Brian Wellington's avatar
Brian Wellington committed
129
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
130
	REQUIRE(rdata1->type == 1);
131
	REQUIRE(rdata1->rdclass == 1);
Mark Andrews's avatar
Mark Andrews committed
132

Brian Wellington's avatar
Brian Wellington committed
133
134
135
	dns_rdata_toregion(rdata1, &r1);
	dns_rdata_toregion(rdata2, &r2);
	return (compare_region(&r1, &r2));
136
137
}

138
static inline isc_result_t
139
fromstruct_in_a(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
Mark Andrews's avatar
Mark Andrews committed
140
141
	        isc_buffer_t *target)
{
Brian Wellington's avatar
Brian Wellington committed
142
143
	UNUSED(source);
	UNUSED(target);
Mark Andrews's avatar
Mark Andrews committed
144

Mark Andrews's avatar
Mark Andrews committed
145
	REQUIRE(type == 1);
146
	REQUIRE(rdclass == 1);
Mark Andrews's avatar
Mark Andrews committed
147

148
	return (ISC_R_NOTIMPLEMENTED);
149
150
}

151
static inline isc_result_t
152
tostruct_in_a(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
153
154
155
	dns_rdata_in_a_t *a = target;
	isc_uint32_t n;
	isc_region_t region;
Mark Andrews's avatar
Mark Andrews committed
156

Brian Wellington's avatar
Brian Wellington committed
157
158
	UNUSED(mctx);

Mark Andrews's avatar
Mark Andrews committed
159
	REQUIRE(rdata->type == 1);
160
	REQUIRE(rdata->rdclass == 1);
Mark Andrews's avatar
Mark Andrews committed
161

162
163
164
165
166
167
168
169
	a->common.rdclass = rdata->rdclass;
	a->common.rdtype = rdata->type;
	ISC_LINK_INIT(&a->common, link);

	dns_rdata_toregion(rdata, &region);
	n = uint32_fromregion(&region);
	a->in_addr.s_addr = htonl(n);

170
	return (ISC_R_SUCCESS);
171
}
172

173
static inline void
174
175
176
freestruct_in_a(void *source) {
	REQUIRE(source != NULL);
	REQUIRE(ISC_FALSE);	/*XXX*/
177
178
	
	UNUSED(source);
179
}
180

181
static inline isc_result_t
182
183
184
additionaldata_in_a(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
		    void *arg)
{
Brian Wellington's avatar
Brian Wellington committed
185
186
187
	REQUIRE(rdata->type == 1);
	REQUIRE(rdata->rdclass == 1);

188
189
190
191
	UNUSED(rdata);
	UNUSED(add);
	UNUSED(arg);

192
	return (ISC_R_SUCCESS);
193
194
}

195
static inline isc_result_t
196
197
198
199
200
201
202
203
204
205
206
digest_in_a(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
	isc_region_t r;

	REQUIRE(rdata->type == 1);
	REQUIRE(rdata->rdclass == 1);

	dns_rdata_toregion(rdata, &r);

	return ((digest)(arg, &r));
}

207
#endif	/* RDATA_IN_1_A_1_C */