1 /* $NetBSD: nsap_22.c,v 1.5 2014/12/10 04:37:59 christos Exp $ */
4 * Copyright (C) 2004, 2005, 2007, 2009, 2013 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: nsap_22.c,v 1.44 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Fri Mar 17 10:41:07 PST 2000 by gson */
26 #ifndef RDATA_IN_1_NSAP_22_C
27 #define RDATA_IN_1_NSAP_22_C
29 #define RRTYPE_NSAP_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_in_nsap(ARGS_FROMTEXT
) {
40 REQUIRE(rdclass
== 1);
48 /* 0x<hex.string.with.periods> */
49 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
51 sr
= &token
.value
.as_textregion
;
53 RETTOK(ISC_R_UNEXPECTEDEND
);
54 if (sr
->base
[0] != '0' || (sr
->base
[1] != 'x' && sr
->base
[1] != 'X'))
56 isc_textregion_consume(sr
, 2);
58 while (sr
->length
> 0) {
59 if (sr
->base
[0] == '.') {
60 isc_textregion_consume(sr
, 1);
63 if ((n
= hexvalue(sr
->base
[0])) == -1)
68 RETERR(mem_tobuffer(target
, &c
, 1));
71 isc_textregion_consume(sr
, 1);
74 RETTOK(ISC_R_UNEXPECTEDEND
);
75 return (ISC_R_SUCCESS
);
78 static inline isc_result_t
79 totext_in_nsap(ARGS_TOTEXT
) {
81 char buf
[sizeof("xx")];
83 REQUIRE(rdata
->type
== 22);
84 REQUIRE(rdata
->rdclass
== 1);
85 REQUIRE(rdata
->length
!= 0);
89 dns_rdata_toregion(rdata
, ®ion
);
90 RETERR(str_totext("0x", target
));
91 while (region
.length
!= 0) {
92 sprintf(buf
, "%02x", region
.base
[0]);
93 isc_region_consume(®ion
, 1);
94 RETERR(str_totext(buf
, target
));
96 return (ISC_R_SUCCESS
);
99 static inline isc_result_t
100 fromwire_in_nsap(ARGS_FROMWIRE
) {
104 REQUIRE(rdclass
== 1);
111 isc_buffer_activeregion(source
, ®ion
);
112 if (region
.length
< 1)
113 return (ISC_R_UNEXPECTEDEND
);
115 RETERR(mem_tobuffer(target
, region
.base
, region
.length
));
116 isc_buffer_forward(source
, region
.length
);
117 return (ISC_R_SUCCESS
);
120 static inline isc_result_t
121 towire_in_nsap(ARGS_TOWIRE
) {
122 REQUIRE(rdata
->type
== 22);
123 REQUIRE(rdata
->rdclass
== 1);
124 REQUIRE(rdata
->length
!= 0);
128 return (mem_tobuffer(target
, rdata
->data
, rdata
->length
));
132 compare_in_nsap(ARGS_COMPARE
) {
136 REQUIRE(rdata1
->type
== rdata2
->type
);
137 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
138 REQUIRE(rdata1
->type
== 22);
139 REQUIRE(rdata1
->rdclass
== 1);
140 REQUIRE(rdata1
->length
!= 0);
141 REQUIRE(rdata2
->length
!= 0);
143 dns_rdata_toregion(rdata1
, &r1
);
144 dns_rdata_toregion(rdata2
, &r2
);
145 return (isc_region_compare(&r1
, &r2
));
148 static inline isc_result_t
149 fromstruct_in_nsap(ARGS_FROMSTRUCT
) {
150 dns_rdata_in_nsap_t
*nsap
= source
;
153 REQUIRE(rdclass
== 1);
154 REQUIRE(source
!= NULL
);
155 REQUIRE(nsap
->common
.rdtype
== type
);
156 REQUIRE(nsap
->common
.rdclass
== rdclass
);
157 REQUIRE(nsap
->nsap
!= NULL
|| nsap
->nsap_len
== 0);
162 return (mem_tobuffer(target
, nsap
->nsap
, nsap
->nsap_len
));
165 static inline isc_result_t
166 tostruct_in_nsap(ARGS_TOSTRUCT
) {
167 dns_rdata_in_nsap_t
*nsap
= target
;
170 REQUIRE(rdata
->type
== 22);
171 REQUIRE(rdata
->rdclass
== 1);
172 REQUIRE(target
!= NULL
);
173 REQUIRE(rdata
->length
!= 0);
175 nsap
->common
.rdclass
= rdata
->rdclass
;
176 nsap
->common
.rdtype
= rdata
->type
;
177 ISC_LINK_INIT(&nsap
->common
, link
);
179 dns_rdata_toregion(rdata
, &r
);
180 nsap
->nsap_len
= r
.length
;
181 nsap
->nsap
= mem_maybedup(mctx
, r
.base
, r
.length
);
182 if (nsap
->nsap
== NULL
)
183 return (ISC_R_NOMEMORY
);
186 return (ISC_R_SUCCESS
);
190 freestruct_in_nsap(ARGS_FREESTRUCT
) {
191 dns_rdata_in_nsap_t
*nsap
= source
;
193 REQUIRE(source
!= NULL
);
194 REQUIRE(nsap
->common
.rdclass
== 1);
195 REQUIRE(nsap
->common
.rdtype
== 22);
197 if (nsap
->mctx
== NULL
)
200 if (nsap
->nsap
!= NULL
)
201 isc_mem_free(nsap
->mctx
, nsap
->nsap
);
205 static inline isc_result_t
206 additionaldata_in_nsap(ARGS_ADDLDATA
) {
207 REQUIRE(rdata
->type
== 22);
208 REQUIRE(rdata
->rdclass
== 1);
214 return (ISC_R_SUCCESS
);
217 static inline isc_result_t
218 digest_in_nsap(ARGS_DIGEST
) {
221 REQUIRE(rdata
->type
== 22);
222 REQUIRE(rdata
->rdclass
== 1);
224 dns_rdata_toregion(rdata
, &r
);
226 return ((digest
)(arg
, &r
));
229 static inline isc_boolean_t
230 checkowner_in_nsap(ARGS_CHECKOWNER
) {
233 REQUIRE(rdclass
== 1);
243 static inline isc_boolean_t
244 checknames_in_nsap(ARGS_CHECKNAMES
) {
246 REQUIRE(rdata
->type
== 22);
247 REQUIRE(rdata
->rdclass
== 1);
257 casecompare_in_nsap(ARGS_COMPARE
) {
258 return (compare_in_nsap(rdata1
, rdata2
));
261 #endif /* RDATA_IN_1_NSAP_22_C */