4 * Copyright (C) 2004, 2005, 2007, 2009 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);
59 while (sr
->length
> 0) {
60 if (sr
->base
[0] == '.') {
61 isc_textregion_consume(sr
, 1);
64 if ((n
= hexvalue(sr
->base
[0])) == -1)
69 RETERR(mem_tobuffer(target
, &c
, 1));
72 isc_textregion_consume(sr
, 1);
75 RETTOK(ISC_R_UNEXPECTEDEND
);
76 return (ISC_R_SUCCESS
);
79 static inline isc_result_t
80 totext_in_nsap(ARGS_TOTEXT
) {
82 char buf
[sizeof("xx")];
84 REQUIRE(rdata
->type
== 22);
85 REQUIRE(rdata
->rdclass
== 1);
86 REQUIRE(rdata
->length
!= 0);
90 dns_rdata_toregion(rdata
, ®ion
);
91 RETERR(str_totext("0x", target
));
92 while (region
.length
!= 0) {
93 sprintf(buf
, "%02x", region
.base
[0]);
94 isc_region_consume(®ion
, 1);
95 RETERR(str_totext(buf
, target
));
97 return (ISC_R_SUCCESS
);
100 static inline isc_result_t
101 fromwire_in_nsap(ARGS_FROMWIRE
) {
105 REQUIRE(rdclass
== 1);
112 isc_buffer_activeregion(source
, ®ion
);
113 if (region
.length
< 1)
114 return (ISC_R_UNEXPECTEDEND
);
116 RETERR(mem_tobuffer(target
, region
.base
, region
.length
));
117 isc_buffer_forward(source
, region
.length
);
118 return (ISC_R_SUCCESS
);
121 static inline isc_result_t
122 towire_in_nsap(ARGS_TOWIRE
) {
123 REQUIRE(rdata
->type
== 22);
124 REQUIRE(rdata
->rdclass
== 1);
125 REQUIRE(rdata
->length
!= 0);
129 return (mem_tobuffer(target
, rdata
->data
, rdata
->length
));
133 compare_in_nsap(ARGS_COMPARE
) {
137 REQUIRE(rdata1
->type
== rdata2
->type
);
138 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
139 REQUIRE(rdata1
->type
== 22);
140 REQUIRE(rdata1
->rdclass
== 1);
141 REQUIRE(rdata1
->length
!= 0);
142 REQUIRE(rdata2
->length
!= 0);
144 dns_rdata_toregion(rdata1
, &r1
);
145 dns_rdata_toregion(rdata2
, &r2
);
146 return (isc_region_compare(&r1
, &r2
));
149 static inline isc_result_t
150 fromstruct_in_nsap(ARGS_FROMSTRUCT
) {
151 dns_rdata_in_nsap_t
*nsap
= source
;
154 REQUIRE(rdclass
== 1);
155 REQUIRE(source
!= NULL
);
156 REQUIRE(nsap
->common
.rdtype
== type
);
157 REQUIRE(nsap
->common
.rdclass
== rdclass
);
158 REQUIRE(nsap
->nsap
!= NULL
|| nsap
->nsap_len
== 0);
163 return (mem_tobuffer(target
, nsap
->nsap
, nsap
->nsap_len
));
166 static inline isc_result_t
167 tostruct_in_nsap(ARGS_TOSTRUCT
) {
168 dns_rdata_in_nsap_t
*nsap
= target
;
171 REQUIRE(rdata
->type
== 22);
172 REQUIRE(rdata
->rdclass
== 1);
173 REQUIRE(target
!= NULL
);
174 REQUIRE(rdata
->length
!= 0);
176 nsap
->common
.rdclass
= rdata
->rdclass
;
177 nsap
->common
.rdtype
= rdata
->type
;
178 ISC_LINK_INIT(&nsap
->common
, link
);
180 dns_rdata_toregion(rdata
, &r
);
181 nsap
->nsap_len
= r
.length
;
182 nsap
->nsap
= mem_maybedup(mctx
, r
.base
, r
.length
);
183 if (nsap
->nsap
== NULL
)
184 return (ISC_R_NOMEMORY
);
187 return (ISC_R_SUCCESS
);
191 freestruct_in_nsap(ARGS_FREESTRUCT
) {
192 dns_rdata_in_nsap_t
*nsap
= source
;
194 REQUIRE(source
!= NULL
);
195 REQUIRE(nsap
->common
.rdclass
== 1);
196 REQUIRE(nsap
->common
.rdtype
== 22);
198 if (nsap
->mctx
== NULL
)
201 if (nsap
->nsap
!= NULL
)
202 isc_mem_free(nsap
->mctx
, nsap
->nsap
);
206 static inline isc_result_t
207 additionaldata_in_nsap(ARGS_ADDLDATA
) {
208 REQUIRE(rdata
->type
== 22);
209 REQUIRE(rdata
->rdclass
== 1);
215 return (ISC_R_SUCCESS
);
218 static inline isc_result_t
219 digest_in_nsap(ARGS_DIGEST
) {
222 REQUIRE(rdata
->type
== 22);
223 REQUIRE(rdata
->rdclass
== 1);
225 dns_rdata_toregion(rdata
, &r
);
227 return ((digest
)(arg
, &r
));
230 static inline isc_boolean_t
231 checkowner_in_nsap(ARGS_CHECKOWNER
) {
234 REQUIRE(rdclass
== 1);
244 static inline isc_boolean_t
245 checknames_in_nsap(ARGS_CHECKNAMES
) {
247 REQUIRE(rdata
->type
== 22);
248 REQUIRE(rdata
->rdclass
== 1);
258 casecompare_in_nsap(ARGS_COMPARE
) {
259 return (compare_in_nsap(rdata1
, rdata2
));
262 #endif /* RDATA_IN_1_NSAP_22_C */