1 /* $NetBSD: a_1.c,v 1.5 2014/12/10 04:37:59 christos Exp $ */
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
31 #define RRTYPE_A_ATTRIBUTES (0)
33 static inline isc_result_t
34 fromtext_in_a(ARGS_FROMTEXT
) {
40 REQUIRE(rdclass
== 1);
47 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
50 if (getquad(DNS_AS_STR(token
), &addr
, lexer
, callbacks
) != 1)
51 RETTOK(DNS_R_BADDOTTEDQUAD
);
52 isc_buffer_availableregion(target
, ®ion
);
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
) {
64 REQUIRE(rdata
->type
== 1);
65 REQUIRE(rdata
->rdclass
== 1);
66 REQUIRE(rdata
->length
== 4);
70 dns_rdata_toregion(rdata
, ®ion
);
71 return (inet_totext(AF_INET
, ®ion
, target
));
74 static inline isc_result_t
75 fromwire_in_a(ARGS_FROMWIRE
) {
80 REQUIRE(rdclass
== 1);
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
) {
104 REQUIRE(rdata
->type
== 1);
105 REQUIRE(rdata
->rdclass
== 1);
106 REQUIRE(rdata
->length
== 4);
110 isc_buffer_availableregion(target
, ®ion
);
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
);
119 compare_in_a(ARGS_COMPARE
) {
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
;
141 REQUIRE(rdclass
== 1);
142 REQUIRE(source
!= NULL
);
143 REQUIRE(a
->common
.rdtype
== type
);
144 REQUIRE(a
->common
.rdclass
== 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
;
161 REQUIRE(rdata
->type
== 1);
162 REQUIRE(rdata
->rdclass
== 1);
163 REQUIRE(rdata
->length
== 4);
167 a
->common
.rdclass
= rdata
->rdclass
;
168 a
->common
.rdtype
= rdata
->type
;
169 ISC_LINK_INIT(&a
->common
, link
);
171 dns_rdata_toregion(rdata
, ®ion
);
172 n
= uint32_fromregion(®ion
);
173 a
->in_addr
.s_addr
= htonl(n
);
175 return (ISC_R_SUCCESS
);
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);
189 static inline isc_result_t
190 additionaldata_in_a(ARGS_ADDLDATA
) {
191 REQUIRE(rdata
->type
== 1);
192 REQUIRE(rdata
->rdclass
== 1);
198 return (ISC_R_SUCCESS
);
201 static inline isc_result_t
202 digest_in_a(ARGS_DIGEST
) {
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
) {
217 REQUIRE(rdclass
== 1);
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);
239 casecompare_in_a(ARGS_COMPARE
) {
240 return (compare_in_a(rdata1
, rdata2
));
243 #endif /* RDATA_IN_1_A_1_C */