1 /* $NetBSD: l32_105.c,v 1.1.1.4 2014/12/10 03:34:42 christos Exp $ */
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
26 #define RRTYPE_L32_ATTRIBUTES (0)
28 static inline isc_result_t
29 fromtext_l32(ARGS_FROMTEXT
) {
42 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
44 if (token
.value
.as_ulong
> 0xffffU
)
46 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
48 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
51 if (getquad(DNS_AS_STR(token
), &addr
, lexer
, callbacks
) != 1)
52 RETTOK(DNS_R_BADDOTTEDQUAD
);
53 isc_buffer_availableregion(target
, ®ion
);
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
) {
64 char buf
[sizeof("65000")];
67 REQUIRE(rdata
->type
== 105);
68 REQUIRE(rdata
->length
== 6);
72 dns_rdata_toregion(rdata
, ®ion
);
73 num
= uint16_fromregion(®ion
);
74 isc_region_consume(®ion
, 2);
75 sprintf(buf
, "%u", num
);
76 RETERR(str_totext(buf
, target
));
78 RETERR(str_totext(" ", target
));
80 return (inet_totext(AF_INET
, ®ion
, target
));
83 static inline isc_result_t
84 fromwire_l32(ARGS_FROMWIRE
) {
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);
109 return (mem_tobuffer(target
, rdata
->data
, rdata
->length
));
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
, ®ion1
);
124 dns_rdata_toregion(rdata2
, ®ion2
);
125 return (isc_region_compare(®ion1
, ®ion2
));
128 static inline isc_result_t
129 fromstruct_l32(ARGS_FROMSTRUCT
) {
130 dns_rdata_l32_t
*l32
= source
;
133 REQUIRE(type
== 105);
134 REQUIRE(source
!= NULL
);
135 REQUIRE(l32
->common
.rdtype
== type
);
136 REQUIRE(l32
->common
.rdclass
== 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
) {
149 dns_rdata_l32_t
*l32
= target
;
152 REQUIRE(rdata
->type
== 105);
153 REQUIRE(target
!= NULL
);
154 REQUIRE(rdata
->length
== 6);
158 l32
->common
.rdclass
= rdata
->rdclass
;
159 l32
->common
.rdtype
= rdata
->type
;
160 ISC_LINK_INIT(&l32
->common
, link
);
162 dns_rdata_toregion(rdata
, ®ion
);
163 l32
->pref
= uint16_fromregion(®ion
);
164 n
= uint32_fromregion(®ion
);
165 l32
->l32
.s_addr
= htonl(n
);
166 return (ISC_R_SUCCESS
);
170 freestruct_l32(ARGS_FREESTRUCT
) {
171 dns_rdata_l32_t
*l32
= source
;
173 REQUIRE(source
!= NULL
);
174 REQUIRE(l32
->common
.rdtype
== 105);
179 static inline isc_result_t
180 additionaldata_l32(ARGS_ADDLDATA
) {
182 REQUIRE(rdata
->type
== 105);
183 REQUIRE(rdata
->length
== 6);
189 return (ISC_R_SUCCESS
);
192 static inline isc_result_t
193 digest_l32(ARGS_DIGEST
) {
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);
217 static inline isc_boolean_t
218 checknames_l32(ARGS_CHECKNAMES
) {
220 REQUIRE(rdata
->type
== 105);
221 REQUIRE(rdata
->length
== 6);
231 casecompare_l32(ARGS_COMPARE
) {
232 return (compare_l32(rdata1
, rdata2
));
235 #endif /* RDATA_GENERIC_L32_105_C */