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) 1999-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.33 2009/12/04 22:06:37 tbox Exp */
22 /* reviewed: Thu Mar 16 15:58:36 PST 2000 by brister */
24 #ifndef RDATA_HS_4_A_1_C
25 #define RDATA_HS_4_A_1_C
29 #define RRTYPE_A_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_hs_a(ARGS_FROMTEXT
) {
38 REQUIRE(rdclass
== 4);
45 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
48 if (getquad(DNS_AS_STR(token
), &addr
, lexer
, callbacks
) != 1)
49 RETTOK(DNS_R_BADDOTTEDQUAD
);
50 isc_buffer_availableregion(target
, ®ion
);
51 if (region
.length
< 4)
52 return (ISC_R_NOSPACE
);
53 memmove(region
.base
, &addr
, 4);
54 isc_buffer_add(target
, 4);
55 return (ISC_R_SUCCESS
);
58 static inline isc_result_t
59 totext_hs_a(ARGS_TOTEXT
) {
62 REQUIRE(rdata
->type
== 1);
63 REQUIRE(rdata
->rdclass
== 4);
64 REQUIRE(rdata
->length
== 4);
68 dns_rdata_toregion(rdata
, ®ion
);
69 return (inet_totext(AF_INET
, ®ion
, target
));
72 static inline isc_result_t
73 fromwire_hs_a(ARGS_FROMWIRE
) {
78 REQUIRE(rdclass
== 4);
85 isc_buffer_activeregion(source
, &sregion
);
86 isc_buffer_availableregion(target
, &tregion
);
87 if (sregion
.length
< 4)
88 return (ISC_R_UNEXPECTEDEND
);
89 if (tregion
.length
< 4)
90 return (ISC_R_NOSPACE
);
92 memmove(tregion
.base
, sregion
.base
, 4);
93 isc_buffer_forward(source
, 4);
94 isc_buffer_add(target
, 4);
95 return (ISC_R_SUCCESS
);
98 static inline isc_result_t
99 towire_hs_a(ARGS_TOWIRE
) {
102 REQUIRE(rdata
->type
== 1);
103 REQUIRE(rdata
->rdclass
== 4);
104 REQUIRE(rdata
->length
== 4);
108 isc_buffer_availableregion(target
, ®ion
);
109 if (region
.length
< rdata
->length
)
110 return (ISC_R_NOSPACE
);
111 memmove(region
.base
, rdata
->data
, rdata
->length
);
112 isc_buffer_add(target
, 4);
113 return (ISC_R_SUCCESS
);
117 compare_hs_a(ARGS_COMPARE
) {
120 REQUIRE(rdata1
->type
== rdata2
->type
);
121 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
122 REQUIRE(rdata1
->type
== 1);
123 REQUIRE(rdata1
->rdclass
== 4);
124 REQUIRE(rdata1
->length
== 4);
125 REQUIRE(rdata2
->length
== 4);
127 order
= memcmp(rdata1
->data
, rdata2
->data
, 4);
129 order
= (order
< 0) ? -1 : 1;
134 static inline isc_result_t
135 fromstruct_hs_a(ARGS_FROMSTRUCT
) {
136 dns_rdata_hs_a_t
*a
= source
;
140 REQUIRE(rdclass
== 4);
141 REQUIRE(source
!= NULL
);
142 REQUIRE(a
->common
.rdtype
== type
);
143 REQUIRE(a
->common
.rdclass
== rdclass
);
148 n
= ntohl(a
->in_addr
.s_addr
);
150 return (uint32_tobuffer(n
, target
));
153 static inline isc_result_t
154 tostruct_hs_a(ARGS_TOSTRUCT
) {
155 dns_rdata_hs_a_t
*a
= target
;
159 REQUIRE(rdata
->type
== 1);
160 REQUIRE(rdata
->rdclass
== 4);
161 REQUIRE(rdata
->length
== 4);
165 a
->common
.rdclass
= rdata
->rdclass
;
166 a
->common
.rdtype
= rdata
->type
;
167 ISC_LINK_INIT(&a
->common
, link
);
169 dns_rdata_toregion(rdata
, ®ion
);
170 n
= uint32_fromregion(®ion
);
171 a
->in_addr
.s_addr
= htonl(n
);
173 return (ISC_R_SUCCESS
);
177 freestruct_hs_a(ARGS_FREESTRUCT
) {
180 REQUIRE(source
!= NULL
);
183 static inline isc_result_t
184 additionaldata_hs_a(ARGS_ADDLDATA
) {
185 REQUIRE(rdata
->type
== 1);
186 REQUIRE(rdata
->rdclass
== 4);
192 return (ISC_R_SUCCESS
);
195 static inline isc_result_t
196 digest_hs_a(ARGS_DIGEST
) {
199 REQUIRE(rdata
->type
== 1);
200 REQUIRE(rdata
->rdclass
== 4);
202 dns_rdata_toregion(rdata
, &r
);
204 return ((digest
)(arg
, &r
));
207 static inline isc_boolean_t
208 checkowner_hs_a(ARGS_CHECKOWNER
) {
211 REQUIRE(rdclass
== 4);
221 static inline isc_boolean_t
222 checknames_hs_a(ARGS_CHECKNAMES
) {
224 REQUIRE(rdata
->type
== 1);
225 REQUIRE(rdata
->rdclass
== 4);
235 casecompare_hs_a(ARGS_COMPARE
) {
236 return (compare_hs_a(rdata1
, rdata2
));
239 #endif /* RDATA_HS_4_A_1_C */