2 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2002 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: nsap_22.c,v 1.42 2007/06/19 23:47:17 tbox Exp $ */
20 /* Reviewed: Fri Mar 17 10:41:07 PST 2000 by gson */
24 #ifndef RDATA_IN_1_NSAP_22_C
25 #define RDATA_IN_1_NSAP_22_C
27 #define RRTYPE_NSAP_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_in_nsap(ARGS_FROMTEXT
) {
38 REQUIRE(rdclass
== 1);
46 /* 0x<hex.string.with.periods> */
47 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
49 sr
= &token
.value
.as_textregion
;
51 RETTOK(ISC_R_UNEXPECTEDEND
);
52 if (sr
->base
[0] != '0' || (sr
->base
[1] != 'x' && sr
->base
[1] != 'X'))
54 isc_textregion_consume(sr
, 2);
57 while (sr
->length
> 0) {
58 if (sr
->base
[0] == '.') {
59 isc_textregion_consume(sr
, 1);
62 if ((n
= hexvalue(sr
->base
[0])) == -1)
67 RETERR(mem_tobuffer(target
, &c
, 1));
70 isc_textregion_consume(sr
, 1);
73 RETTOK(ISC_R_UNEXPECTEDEND
);
74 return (ISC_R_SUCCESS
);
77 static inline isc_result_t
78 totext_in_nsap(ARGS_TOTEXT
) {
80 char buf
[sizeof("xx")];
82 REQUIRE(rdata
->type
== 22);
83 REQUIRE(rdata
->rdclass
== 1);
84 REQUIRE(rdata
->length
!= 0);
88 dns_rdata_toregion(rdata
, ®ion
);
89 RETERR(str_totext("0x", target
));
90 while (region
.length
!= 0) {
91 sprintf(buf
, "%02x", region
.base
[0]);
92 isc_region_consume(®ion
, 1);
93 RETERR(str_totext(buf
, target
));
95 return (ISC_R_SUCCESS
);
98 static inline isc_result_t
99 fromwire_in_nsap(ARGS_FROMWIRE
) {
103 REQUIRE(rdclass
== 1);
110 isc_buffer_activeregion(source
, ®ion
);
111 if (region
.length
< 1)
112 return (ISC_R_UNEXPECTEDEND
);
114 RETERR(mem_tobuffer(target
, region
.base
, region
.length
));
115 isc_buffer_forward(source
, region
.length
);
116 return (ISC_R_SUCCESS
);
119 static inline isc_result_t
120 towire_in_nsap(ARGS_TOWIRE
) {
121 REQUIRE(rdata
->type
== 22);
122 REQUIRE(rdata
->rdclass
== 1);
123 REQUIRE(rdata
->length
!= 0);
127 return (mem_tobuffer(target
, rdata
->data
, rdata
->length
));
131 compare_in_nsap(ARGS_COMPARE
) {
135 REQUIRE(rdata1
->type
== rdata2
->type
);
136 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
137 REQUIRE(rdata1
->type
== 22);
138 REQUIRE(rdata1
->rdclass
== 1);
139 REQUIRE(rdata1
->length
!= 0);
140 REQUIRE(rdata2
->length
!= 0);
142 dns_rdata_toregion(rdata1
, &r1
);
143 dns_rdata_toregion(rdata2
, &r2
);
144 return (isc_region_compare(&r1
, &r2
));
147 static inline isc_result_t
148 fromstruct_in_nsap(ARGS_FROMSTRUCT
) {
149 dns_rdata_in_nsap_t
*nsap
= source
;
152 REQUIRE(rdclass
== 1);
153 REQUIRE(source
!= NULL
);
154 REQUIRE(nsap
->common
.rdtype
== type
);
155 REQUIRE(nsap
->common
.rdclass
== rdclass
);
156 REQUIRE(nsap
->nsap
!= NULL
|| nsap
->nsap_len
== 0);
161 return (mem_tobuffer(target
, nsap
->nsap
, nsap
->nsap_len
));
164 static inline isc_result_t
165 tostruct_in_nsap(ARGS_TOSTRUCT
) {
166 dns_rdata_in_nsap_t
*nsap
= target
;
169 REQUIRE(rdata
->type
== 22);
170 REQUIRE(rdata
->rdclass
== 1);
171 REQUIRE(target
!= NULL
);
172 REQUIRE(rdata
->length
!= 0);
174 nsap
->common
.rdclass
= rdata
->rdclass
;
175 nsap
->common
.rdtype
= rdata
->type
;
176 ISC_LINK_INIT(&nsap
->common
, link
);
178 dns_rdata_toregion(rdata
, &r
);
179 nsap
->nsap_len
= r
.length
;
180 nsap
->nsap
= mem_maybedup(mctx
, r
.base
, r
.length
);
181 if (nsap
->nsap
== NULL
)
182 return (ISC_R_NOMEMORY
);
185 return (ISC_R_SUCCESS
);
189 freestruct_in_nsap(ARGS_FREESTRUCT
) {
190 dns_rdata_in_nsap_t
*nsap
= source
;
192 REQUIRE(source
!= NULL
);
193 REQUIRE(nsap
->common
.rdclass
== 1);
194 REQUIRE(nsap
->common
.rdtype
== 22);
196 if (nsap
->mctx
== NULL
)
199 if (nsap
->nsap
!= NULL
)
200 isc_mem_free(nsap
->mctx
, nsap
->nsap
);
204 static inline isc_result_t
205 additionaldata_in_nsap(ARGS_ADDLDATA
) {
206 REQUIRE(rdata
->type
== 22);
207 REQUIRE(rdata
->rdclass
== 1);
213 return (ISC_R_SUCCESS
);
216 static inline isc_result_t
217 digest_in_nsap(ARGS_DIGEST
) {
220 REQUIRE(rdata
->type
== 22);
221 REQUIRE(rdata
->rdclass
== 1);
223 dns_rdata_toregion(rdata
, &r
);
225 return ((digest
)(arg
, &r
));
228 static inline isc_boolean_t
229 checkowner_in_nsap(ARGS_CHECKOWNER
) {
232 REQUIRE(rdclass
== 1);
242 static inline isc_boolean_t
243 checknames_in_nsap(ARGS_CHECKNAMES
) {
245 REQUIRE(rdata
->type
== 22);
246 REQUIRE(rdata
->rdclass
== 1);
255 #endif /* RDATA_IN_1_NSAP_22_C */