4 * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2003 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: rdata_test.c,v 1.48 2007/06/19 23:46:59 tbox Exp */
26 #include <isc/buffer.h>
27 #include <isc/commandline.h>
30 #include <isc/string.h>
33 #include <dns/rdata.h>
34 #include <dns/compress.h>
35 #include <dns/rdataclass.h>
36 #include <dns/rdatastruct.h>
37 #include <dns/rdatatype.h>
38 #include <dns/result.h>
43 isc_lexspecials_t specials
;
46 viastruct(dns_rdata_t
*rdata
, isc_mem_t
*mctx
,
47 dns_rdata_t
*rdata2
, isc_buffer_t
*b
)
51 isc_boolean_t need_free
= ISC_FALSE
;
55 UNUSED(rdata2
); /* XXXMPA remove when fromstruct is ready. */
58 switch (rdata
->type
) {
59 case dns_rdatatype_a6
: {
60 dns_rdata_in_a6_t in_a6
;
61 result
= dns_rdata_tostruct(rdata
, sp
= &in_a6
, NULL
);
64 case dns_rdatatype_a
: {
65 switch (rdata
->rdclass
) {
66 case dns_rdataclass_hs
: {
67 dns_rdata_hs_a_t hs_a
;
68 result
= dns_rdata_tostruct(rdata
, sp
= &hs_a
, NULL
);
71 case dns_rdataclass_in
: {
72 dns_rdata_in_a_t in_a
;
73 result
= dns_rdata_tostruct(rdata
, sp
= &in_a
, NULL
);
77 result
= ISC_R_NOTIMPLEMENTED
;
82 case dns_rdatatype_aaaa
: {
83 dns_rdata_in_aaaa_t in_aaaa
;
84 result
= dns_rdata_tostruct(rdata
, sp
= &in_aaaa
, NULL
);
87 case dns_rdatatype_afsdb
: {
88 dns_rdata_afsdb_t afsdb
;
89 result
= dns_rdata_tostruct(rdata
, sp
= &afsdb
, NULL
);
92 case dns_rdatatype_any
: {
93 result
= ISC_R_NOTIMPLEMENTED
;
96 case dns_rdatatype_apl
: {
97 switch (rdata
->rdclass
) {
98 case dns_rdataclass_in
: {
99 dns_rdata_in_apl_t in_apl
;
100 result
= dns_rdata_tostruct(rdata
, sp
= &in_apl
, NULL
);
104 result
= ISC_R_NOTIMPLEMENTED
;
109 case dns_rdatatype_cert
: {
110 dns_rdata_cert_t cert
;
111 result
= dns_rdata_tostruct(rdata
, sp
= &cert
, NULL
);
114 case dns_rdatatype_cname
: {
115 dns_rdata_cname_t cname
;
116 result
= dns_rdata_tostruct(rdata
, sp
= &cname
, NULL
);
119 case dns_rdatatype_dname
: {
120 dns_rdata_dname_t dname
;
121 result
= dns_rdata_tostruct(rdata
, sp
= &dname
, NULL
);
124 case dns_rdatatype_gpos
: {
125 dns_rdata_gpos_t gpos
;
126 result
= dns_rdata_tostruct(rdata
, sp
= &gpos
, NULL
);
129 case dns_rdatatype_hinfo
: {
130 dns_rdata_hinfo_t hinfo
;
131 result
= dns_rdata_tostruct(rdata
, sp
= &hinfo
, NULL
);
134 case dns_rdatatype_isdn
: {
135 dns_rdata_isdn_t isdn
;
136 result
= dns_rdata_tostruct(rdata
, sp
= &isdn
, NULL
);
139 case dns_rdatatype_key
: {
141 result
= dns_rdata_tostruct(rdata
, sp
= &key
, NULL
);
144 case dns_rdatatype_kx
: {
145 dns_rdata_in_kx_t in_kx
;
146 result
= dns_rdata_tostruct(rdata
, sp
= &in_kx
, NULL
);
149 case dns_rdatatype_loc
: {
151 result
= dns_rdata_tostruct(rdata
, sp
= &loc
, NULL
);
154 case dns_rdatatype_mb
: {
156 result
= dns_rdata_tostruct(rdata
, sp
= &mb
, NULL
);
159 case dns_rdatatype_md
: {
161 result
= dns_rdata_tostruct(rdata
, sp
= &md
, NULL
);
164 case dns_rdatatype_mf
: {
166 result
= dns_rdata_tostruct(rdata
, sp
= &mf
, NULL
);
169 case dns_rdatatype_mg
: {
171 result
= dns_rdata_tostruct(rdata
, sp
= &mg
, NULL
);
174 case dns_rdatatype_minfo
: {
175 dns_rdata_minfo_t minfo
;
176 result
= dns_rdata_tostruct(rdata
, sp
= &minfo
, NULL
);
179 case dns_rdatatype_mr
: {
181 result
= dns_rdata_tostruct(rdata
, sp
= &mr
, NULL
);
184 case dns_rdatatype_mx
: {
186 result
= dns_rdata_tostruct(rdata
, sp
= &mx
, NULL
);
189 case dns_rdatatype_naptr
: {
190 dns_rdata_in_naptr_t in_naptr
;
191 result
= dns_rdata_tostruct(rdata
, sp
= &in_naptr
, NULL
);
194 case dns_rdatatype_ns
: {
196 result
= dns_rdata_tostruct(rdata
, sp
= &ns
, NULL
);
199 case dns_rdatatype_nsap
: {
200 dns_rdata_in_nsap_t in_nsap
;
201 result
= dns_rdata_tostruct(rdata
, sp
= &in_nsap
, NULL
);
204 case dns_rdatatype_nsap_ptr
: {
205 dns_rdata_in_nsap_ptr_t in_nsap_ptr
;
206 result
= dns_rdata_tostruct(rdata
, sp
= &in_nsap_ptr
, NULL
);
209 case dns_rdatatype_null
: {
210 dns_rdata_null_t null
;
211 result
= dns_rdata_tostruct(rdata
, sp
= &null
, NULL
);
214 case dns_rdatatype_nxt
: {
216 result
= dns_rdata_tostruct(rdata
, sp
= &nxt
, NULL
);
219 case dns_rdatatype_opt
: {
221 result
= dns_rdata_tostruct(rdata
, sp
= &opt
, NULL
);
224 case dns_rdatatype_ptr
: {
226 result
= dns_rdata_tostruct(rdata
, sp
= &ptr
, NULL
);
229 case dns_rdatatype_px
: {
230 dns_rdata_in_px_t in_px
;
231 result
= dns_rdata_tostruct(rdata
, sp
= &in_px
, NULL
);
234 case dns_rdatatype_rp
: {
236 result
= dns_rdata_tostruct(rdata
, sp
= &rp
, NULL
);
239 case dns_rdatatype_rt
: {
241 result
= dns_rdata_tostruct(rdata
, sp
= &rt
, NULL
);
244 case dns_rdatatype_sig
: {
246 result
= dns_rdata_tostruct(rdata
, sp
= &sig
, NULL
);
249 case dns_rdatatype_soa
: {
251 result
= dns_rdata_tostruct(rdata
, sp
= &soa
, NULL
);
254 case dns_rdatatype_srv
: {
255 dns_rdata_in_srv_t in_srv
;
256 result
= dns_rdata_tostruct(rdata
, sp
= &in_srv
, NULL
);
259 case dns_rdatatype_tkey
: {
260 dns_rdata_tkey_t tkey
;
261 result
= dns_rdata_tostruct(rdata
, sp
= &tkey
, NULL
);
264 case dns_rdatatype_tsig
: {
265 dns_rdata_any_tsig_t tsig
;
266 result
= dns_rdata_tostruct(rdata
, sp
= &tsig
, NULL
);
269 case dns_rdatatype_txt
: {
271 result
= dns_rdata_tostruct(rdata
, sp
= &txt
, NULL
);
274 case dns_rdatatype_spf
: {
276 result
= dns_rdata_tostruct(rdata
, sp
= &spf
, NULL
);
279 case dns_rdatatype_unspec
: {
280 dns_rdata_unspec_t unspec
;
281 result
= dns_rdata_tostruct(rdata
, sp
= &unspec
, NULL
);
284 case dns_rdatatype_wks
: {
285 dns_rdata_in_wks_t in_wks
;
286 result
= dns_rdata_tostruct(rdata
, sp
= &in_wks
, NULL
);
289 case dns_rdatatype_x25
: {
291 result
= dns_rdata_tostruct(rdata
, sp
= &x25
, NULL
);
294 case dns_rdatatype_nsec
: {
295 dns_rdata_nsec_t nsec
;
296 result
= dns_rdata_tostruct(rdata
, sp
= &nsec
, NULL
);
299 case dns_rdatatype_rrsig
: {
300 dns_rdata_rrsig_t rrsig
;
301 result
= dns_rdata_tostruct(rdata
, sp
= &rrsig
, NULL
);
304 case dns_rdatatype_dnskey
: {
305 dns_rdata_dnskey_t dnskey
;
306 result
= dns_rdata_tostruct(rdata
, sp
= &dnskey
, NULL
);
310 result
= ISC_R_NOTIMPLEMENTED
;
313 if (result
!= ISC_R_SUCCESS
)
314 fprintf(stdout
, "viastruct: tostruct %d %d return %s\n",
315 rdata
->type
, rdata
->rdclass
,
316 dns_result_totext(result
));
318 dns_rdata_freestruct(sp
);
320 switch (rdata
->type
) {
321 case dns_rdatatype_a6
: {
322 dns_rdata_in_a6_t in_a6
;
323 result
= dns_rdata_tostruct(rdata
, sp
= &in_a6
, mctx
);
326 case dns_rdatatype_a
: {
327 switch (rdata
->rdclass
) {
328 case dns_rdataclass_hs
: {
329 dns_rdata_hs_a_t hs_a
;
330 result
= dns_rdata_tostruct(rdata
, sp
= &hs_a
, mctx
);
333 case dns_rdataclass_in
: {
334 dns_rdata_in_a_t in_a
;
335 result
= dns_rdata_tostruct(rdata
, sp
= &in_a
, mctx
);
339 result
= ISC_R_NOTIMPLEMENTED
;
344 case dns_rdatatype_aaaa
: {
345 dns_rdata_in_aaaa_t in_aaaa
;
346 result
= dns_rdata_tostruct(rdata
, sp
= &in_aaaa
, mctx
);
349 case dns_rdatatype_afsdb
: {
350 dns_rdata_afsdb_t afsdb
;
351 result
= dns_rdata_tostruct(rdata
, sp
= &afsdb
, mctx
);
354 case dns_rdatatype_any
: {
355 result
= ISC_R_NOTIMPLEMENTED
;
358 case dns_rdatatype_apl
: {
359 switch (rdata
->rdclass
) {
360 case dns_rdataclass_in
: {
361 dns_rdata_in_apl_t in_apl
;
362 result
= dns_rdata_tostruct(rdata
, sp
= &in_apl
, mctx
);
366 result
= ISC_R_NOTIMPLEMENTED
;
371 case dns_rdatatype_cert
: {
372 dns_rdata_cert_t cert
;
373 result
= dns_rdata_tostruct(rdata
, sp
= &cert
, mctx
);
376 case dns_rdatatype_cname
: {
377 dns_rdata_cname_t cname
;
378 result
= dns_rdata_tostruct(rdata
, sp
= &cname
, mctx
);
381 case dns_rdatatype_dname
: {
382 dns_rdata_dname_t dname
;
383 result
= dns_rdata_tostruct(rdata
, sp
= &dname
, mctx
);
386 case dns_rdatatype_gpos
: {
387 dns_rdata_gpos_t gpos
;
388 result
= dns_rdata_tostruct(rdata
, sp
= &gpos
, mctx
);
391 case dns_rdatatype_hinfo
: {
392 dns_rdata_hinfo_t hinfo
;
393 result
= dns_rdata_tostruct(rdata
, sp
= &hinfo
, mctx
);
396 case dns_rdatatype_isdn
: {
397 dns_rdata_isdn_t isdn
;
398 result
= dns_rdata_tostruct(rdata
, sp
= &isdn
, mctx
);
401 case dns_rdatatype_key
: {
403 result
= dns_rdata_tostruct(rdata
, sp
= &key
, mctx
);
406 case dns_rdatatype_kx
: {
407 dns_rdata_in_kx_t in_kx
;
408 result
= dns_rdata_tostruct(rdata
, sp
= &in_kx
, mctx
);
411 case dns_rdatatype_loc
: {
413 result
= dns_rdata_tostruct(rdata
, sp
= &loc
, mctx
);
416 case dns_rdatatype_mb
: {
418 result
= dns_rdata_tostruct(rdata
, sp
= &mb
, mctx
);
421 case dns_rdatatype_md
: {
423 result
= dns_rdata_tostruct(rdata
, sp
= &md
, mctx
);
426 case dns_rdatatype_mf
: {
428 result
= dns_rdata_tostruct(rdata
, sp
= &mf
, mctx
);
431 case dns_rdatatype_mg
: {
433 result
= dns_rdata_tostruct(rdata
, sp
= &mg
, mctx
);
436 case dns_rdatatype_minfo
: {
437 dns_rdata_minfo_t minfo
;
438 result
= dns_rdata_tostruct(rdata
, sp
= &minfo
, mctx
);
441 case dns_rdatatype_mr
: {
443 result
= dns_rdata_tostruct(rdata
, sp
= &mr
, mctx
);
446 case dns_rdatatype_mx
: {
448 result
= dns_rdata_tostruct(rdata
, sp
= &mx
, mctx
);
451 case dns_rdatatype_naptr
: {
452 dns_rdata_in_naptr_t in_naptr
;
453 result
= dns_rdata_tostruct(rdata
, sp
= &in_naptr
, mctx
);
456 case dns_rdatatype_ns
: {
458 result
= dns_rdata_tostruct(rdata
, sp
= &ns
, mctx
);
461 case dns_rdatatype_nsap
: {
462 dns_rdata_in_nsap_t in_nsap
;
463 result
= dns_rdata_tostruct(rdata
, sp
= &in_nsap
, mctx
);
466 case dns_rdatatype_nsap_ptr
: {
467 dns_rdata_in_nsap_ptr_t in_nsap_ptr
;
468 result
= dns_rdata_tostruct(rdata
, sp
= &in_nsap_ptr
, mctx
);
471 case dns_rdatatype_null
: {
472 dns_rdata_null_t null
;
473 result
= dns_rdata_tostruct(rdata
, sp
= &null
, mctx
);
476 case dns_rdatatype_nxt
: {
478 result
= dns_rdata_tostruct(rdata
, sp
= &nxt
, mctx
);
481 case dns_rdatatype_opt
: {
483 result
= dns_rdata_tostruct(rdata
, sp
= &opt
, mctx
);
486 case dns_rdatatype_ptr
: {
488 result
= dns_rdata_tostruct(rdata
, sp
= &ptr
, mctx
);
491 case dns_rdatatype_px
: {
492 dns_rdata_in_px_t in_px
;
493 result
= dns_rdata_tostruct(rdata
, sp
= &in_px
, mctx
);
496 case dns_rdatatype_rp
: {
498 result
= dns_rdata_tostruct(rdata
, sp
= &rp
, mctx
);
501 case dns_rdatatype_rt
: {
503 result
= dns_rdata_tostruct(rdata
, sp
= &rt
, mctx
);
506 case dns_rdatatype_sig
: {
508 result
= dns_rdata_tostruct(rdata
, sp
= &sig
, mctx
);
511 case dns_rdatatype_soa
: {
513 result
= dns_rdata_tostruct(rdata
, sp
= &soa
, mctx
);
516 case dns_rdatatype_srv
: {
517 dns_rdata_in_srv_t in_srv
;
518 result
= dns_rdata_tostruct(rdata
, sp
= &in_srv
, mctx
);
521 case dns_rdatatype_tkey
: {
522 dns_rdata_tkey_t tkey
;
523 result
= dns_rdata_tostruct(rdata
, sp
= &tkey
, mctx
);
526 case dns_rdatatype_tsig
: {
527 dns_rdata_any_tsig_t tsig
;
528 result
= dns_rdata_tostruct(rdata
, sp
= &tsig
, mctx
);
531 case dns_rdatatype_txt
: {
533 result
= dns_rdata_tostruct(rdata
, sp
= &txt
, mctx
);
536 case dns_rdatatype_spf
: {
538 result
= dns_rdata_tostruct(rdata
, sp
= &spf
, mctx
);
541 case dns_rdatatype_unspec
: {
542 dns_rdata_unspec_t unspec
;
543 result
= dns_rdata_tostruct(rdata
, sp
= &unspec
, mctx
);
546 case dns_rdatatype_wks
: {
547 dns_rdata_in_wks_t in_wks
;
548 result
= dns_rdata_tostruct(rdata
, sp
= &in_wks
, mctx
);
551 case dns_rdatatype_x25
: {
553 result
= dns_rdata_tostruct(rdata
, sp
= &x25
, mctx
);
556 case dns_rdatatype_nsec
: {
557 dns_rdata_nsec_t nsec
;
558 result
= dns_rdata_tostruct(rdata
, sp
= &nsec
, mctx
);
561 case dns_rdatatype_rrsig
: {
562 dns_rdata_rrsig_t rrsig
;
563 result
= dns_rdata_tostruct(rdata
, sp
= &rrsig
, mctx
);
566 case dns_rdatatype_dnskey
: {
567 dns_rdata_dnskey_t dnskey
;
568 result
= dns_rdata_tostruct(rdata
, sp
= &dnskey
, mctx
);
572 result
= ISC_R_NOTIMPLEMENTED
;
575 if (result
!= ISC_R_SUCCESS
)
576 fprintf(stdout
, "viastruct: tostruct %d %d return %s\n",
577 rdata
->type
, rdata
->rdclass
,
578 dns_result_totext(result
));
580 need_free
= ISC_TRUE
;
582 rdc
= rdata
->rdclass
;
584 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, sp
, b
);
585 if (result
!= ISC_R_SUCCESS
)
587 "viastruct: fromstruct %d %d return %s\n",
588 rdata
->type
, rdata
->rdclass
,
589 dns_result_totext(result
));
590 else if (rdata
->length
!= rdata2
->length
||
591 memcmp(rdata
->data
, rdata2
->data
, rdata
->length
) != 0)
596 fprintf(stdout
, "viastruct: memcmp failed\n");
598 fprintf(stdout
, "%d %d\n",
599 rdata
->length
, rdata2
->length
);
601 if (rdata2
->length
< l
)
603 for (i
= 0; i
< l
; i
++)
604 fprintf(stdout
, "%02x %02x\n",
605 rdata
->data
[i
], rdata2
->data
[i
]);
609 switch (rdata
->type
) {
610 case dns_rdatatype_a6
: {
611 dns_rdata_in_a6_t in_a6
;
612 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_a6
, b
);
615 case dns_rdatatype_a
: {
616 switch (rdata
->rdclass
) {
617 case dns_rdataclass_hs
: {
618 dns_rdata_hs_a_t hs_a
;
619 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
,
623 case dns_rdataclass_in
: {
624 dns_rdata_in_a_t in_a
;
625 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
,
630 result
= ISC_R_NOTIMPLEMENTED
;
635 case dns_rdatatype_aaaa
: {
636 dns_rdata_in_aaaa_t in_aaaa
;
637 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_aaaa
, b
);
640 case dns_rdatatype_afsdb
: {
641 dns_rdata_afsdb_t afsdb
;
642 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &afsdb
, b
);
645 case dns_rdatatype_any
: {
646 result
= ISC_R_NOTIMPLEMENTED
;
649 case dns_rdatatype_apl
: {
650 switch (rdata
->rdclass
) {
651 case dns_rdataclass_in
: {
652 dns_rdata_in_apl_t in_apl
;
653 result
= dns_rdata_fromstruct(rdata
, rdc
, rdt
, &in_apl
, b
);
657 result
= ISC_R_NOTIMPLEMENTED
;
662 case dns_rdatatype_cert
: {
663 dns_rdata_cert_t cert
;
664 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &cert
, b
);
667 case dns_rdatatype_cname
: {
668 dns_rdata_cname_t cname
;
669 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &cname
, b
);
672 case dns_rdatatype_dname
: {
673 dns_rdata_dname_t dname
;
674 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &dname
, b
);
677 case dns_rdatatype_gpos
: {
678 dns_rdata_gpos_t gpos
;
679 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &gpos
, b
);
682 case dns_rdatatype_hinfo
: {
683 dns_rdata_hinfo_t hinfo
;
684 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &hinfo
, b
);
687 case dns_rdatatype_isdn
: {
688 dns_rdata_isdn_t isdn
;
689 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &isdn
, b
);
692 case dns_rdatatype_key
: {
694 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &key
, b
);
697 case dns_rdatatype_kx
: {
698 dns_rdata_in_kx_t in_kx
;
699 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_kx
, b
);
702 case dns_rdatatype_loc
: {
704 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &loc
, b
);
707 case dns_rdatatype_mb
: {
709 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &mb
, b
);
712 case dns_rdatatype_md
: {
714 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &md
, b
);
717 case dns_rdatatype_mf
: {
719 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &mf
, b
);
722 case dns_rdatatype_mg
: {
724 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &mg
, b
);
727 case dns_rdatatype_minfo
: {
728 dns_rdata_minfo_t minfo
;
729 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &minfo
, b
);
732 case dns_rdatatype_mr
: {
734 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &mr
, b
);
737 case dns_rdatatype_mx
: {
739 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &mx
, b
);
742 case dns_rdatatype_naptr
: {
743 dns_rdata_in_naptr_t in_naptr
;
744 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_naptr
, b
);
747 case dns_rdatatype_ns
: {
749 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &ns
, b
);
752 case dns_rdatatype_nsap
: {
753 dns_rdata_in_nsap_t in_nsap
;
754 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_nsap
, b
);
757 case dns_rdatatype_nsap_ptr
: {
758 dns_rdata_in_nsap_ptr_t in_nsap_ptr
;
759 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_nsap_ptr
,
763 case dns_rdatatype_null
: {
764 dns_rdata_null_t null
;
765 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &null
, b
);
768 case dns_rdatatype_nxt
: {
770 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &nxt
, b
);
773 case dns_rdatatype_opt
: {
775 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &opt
, b
);
778 case dns_rdatatype_ptr
: {
780 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &ptr
, b
);
783 case dns_rdatatype_px
: {
784 dns_rdata_in_px_t in_px
;
785 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_px
, b
);
788 case dns_rdatatype_rp
: {
790 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &rp
, b
);
793 case dns_rdatatype_rt
: {
795 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &rt
, b
);
798 case dns_rdatatype_sig
: {
800 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &sig
, b
);
803 case dns_rdatatype_soa
: {
805 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &soa
, b
);
808 case dns_rdatatype_srv
: {
809 dns_rdata_in_srv_t in_srv
;
810 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_srv
, b
);
813 case dns_rdatatype_tkey
: {
814 dns_rdata_tkey_t tkey
;
815 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &tkey
, b
);
818 case dns_rdatatype_tsig
: {
819 dns_rdata_any_tsig_t tsig
;
820 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &tsig
, b
);
823 case dns_rdatatype_txt
: {
825 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &txt
, b
);
828 case dns_rdatatype_spf
: {
830 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &spf
, b
);
833 case dns_rdatatype_unspec
: {
834 dns_rdata_unspec_t unspec
;
835 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &unspec
, b
);
838 case dns_rdatatype_wks
: {
839 dns_rdata_in_wks_t in_wks
;
840 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_wks
, b
);
843 case dns_rdatatype_x25
: {
845 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &x25
, b
);
848 case dns_rdatatype_nsec
: {
849 dns_rdata_nsec_t nsec
;
850 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &nsec
, b
);
853 case dns_rdatatype_rrsig
: {
854 dns_rdata_rrsig_t rrsig
;
855 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &rrsig
, b
);
858 case dns_rdatatype_dnskey
: {
859 dns_rdata_dnskey_t dnskey
;
860 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &dnskey
, b
);
864 result
= ISC_R_NOTIMPLEMENTED
;
869 dns_rdata_freestruct(sp
);
873 main(int argc
, char *argv
[]) {
879 unsigned int options
= 0;
880 dns_rdatatype_t type
;
881 dns_rdataclass_t
class;
882 dns_rdatatype_t lasttype
= 0;
883 char outbuf
[16*1024];
885 char wirebuf
[16*1024];
886 char viabuf
[16*1024];
890 dns_rdata_t rdata
= DNS_RDATA_INIT
;
891 dns_rdata_t last
= DNS_RDATA_INIT
;
895 dns_decompress_t dctx
;
906 while ((c
= isc_commandline_parse(argc
, argv
, "dqswtarzS")) != -1) {
940 memset(&dctx
, 0, sizeof(dctx
));
941 dctx
.allowed
= DNS_COMPRESS_ALL
;
943 RUNTIME_CHECK(isc_mem_create(0, 0, &mctx
) == ISC_R_SUCCESS
);
944 RUNTIME_CHECK(isc_lex_create(mctx
, 256, &lex
) == ISC_R_SUCCESS
);
947 * Set up to lex DNS master file.
953 isc_lex_setspecials(lex
, specials
);
954 options
= ISC_LEXOPT_EOL
;
955 isc_lex_setcomments(lex
, ISC_LEXCOMMENT_DNSMASTERFILE
);
957 RUNTIME_CHECK(isc_lex_openstream(lex
, stdin
) == ISC_R_SUCCESS
);
959 dns_rdata_init(&last
);
960 while ((result
= isc_lex_gettoken(lex
, options
| ISC_LEXOPT_NUMBER
,
961 &token
)) == ISC_R_SUCCESS
) {
962 if (debug
) fprintf(stdout
, "token.type = %d\n", token
.type
);
964 if (token
.type
== isc_tokentype_eol
)
968 if (token
.type
== isc_tokentype_eof
)
974 if (token
.type
== isc_tokentype_number
) {
975 type
= token
.value
.as_ulong
;
976 isc_buffer_init(&tbuf
, outbuf
, sizeof(outbuf
));
977 result
= dns_rdatatype_totext(type
, &tbuf
);
978 fprintf(stdout
, "type = %.*s(%d)\n",
979 (int)tbuf
.used
, (char*)tbuf
.base
, type
);
980 } else if (token
.type
== isc_tokentype_string
) {
981 result
= dns_rdatatype_fromtext(&type
,
982 &token
.value
.as_textregion
);
983 if (result
!= ISC_R_SUCCESS
) {
985 "dns_rdatatype_fromtext "
987 dns_result_totext(result
), result
);
992 fprintf(stdout
, "type = %.*s(%d)\n",
993 (int)token
.value
.as_textregion
.length
,
994 token
.value
.as_textregion
.base
, type
);
998 result
= isc_lex_gettoken(lex
, options
| ISC_LEXOPT_NUMBER
,
1000 if (result
!= ISC_R_SUCCESS
)
1002 if (token
.type
== isc_tokentype_eol
)
1004 if (token
.type
== isc_tokentype_eof
)
1006 if (token
.type
== isc_tokentype_number
) {
1007 class = token
.value
.as_ulong
;
1008 isc_buffer_init(&tbuf
, outbuf
, sizeof(outbuf
));
1009 result
= dns_rdatatype_totext(class, &tbuf
);
1010 fprintf(stdout
, "class = %.*s(%d)\n",
1011 (int)tbuf
.used
, (char*)tbuf
.base
, class);
1012 } else if (token
.type
== isc_tokentype_string
) {
1013 result
= dns_rdataclass_fromtext(&class,
1014 &token
.value
.as_textregion
);
1015 if (result
!= ISC_R_SUCCESS
) {
1016 fprintf(stdout
, "dns_rdataclass_fromtext "
1017 "returned %s(%d)\n",
1018 dns_result_totext(result
), result
);
1023 fprintf(stdout
, "class = %.*s(%d)\n",
1024 (int)token
.value
.as_textregion
.length
,
1025 token
.value
.as_textregion
.base
, class);
1030 dns_rdata_init(&rdata
);
1031 isc_buffer_init(&dbuf
, inbuf
, sizeof(inbuf
));
1032 result
= dns_rdata_fromtext(&rdata
, class, type
, lex
,
1033 NULL
, 0, mctx
, &dbuf
,
1035 if (result
!= ISC_R_SUCCESS
) {
1037 "dns_rdata_fromtext returned %s(%d)\n",
1038 dns_result_totext(result
), result
);
1044 for (i
= 0; i
< rdata
.length
; /* */ ) {
1045 fprintf(stdout
, "%02x", rdata
.data
[i
]);
1046 if ((++i
% 20) == 0)
1047 fputs("\n", stdout
);
1049 if (i
== rdata
.length
)
1050 fputs("\n", stdout
);
1057 * Convert to wire and back?
1060 result
= dns_compress_init(&cctx
, -1, mctx
);
1061 if (result
!= ISC_R_SUCCESS
) {
1063 "dns_compress_init returned %s(%d)\n",
1064 dns_result_totext(result
), result
);
1067 isc_buffer_init(&wbuf
, wirebuf
, sizeof(wirebuf
));
1068 result
= dns_rdata_towire(&rdata
, &cctx
, &wbuf
);
1069 dns_compress_invalidate(&cctx
);
1070 if (result
!= ISC_R_SUCCESS
) {
1072 "dns_rdata_towire returned %s(%d)\n",
1073 dns_result_totext(result
), result
);
1076 len
= wbuf
.used
- wbuf
.current
;
1079 fputs("\n", stdout
);
1080 for (i
= 0; i
< (unsigned int)len
; /* */ ) {
1081 fprintf(stdout
, "%02x",
1082 ((unsigned char*)wbuf
.base
)[i
+ wbuf
.current
]);
1083 if ((++i
% 20) == 0)
1084 fputs("\n", stdout
);
1087 fputs("\n", stdout
);
1095 len
= (len
* 3) / 4;
1097 isc_buffer_add(&wbuf
, len
/ 4 + 1);
1101 isc_buffer_setactive(&wbuf
, len
);
1102 dns_rdata_init(&rdata
);
1103 isc_buffer_init(&dbuf
, inbuf
, sizeof(inbuf
));
1104 dns_decompress_init(&dctx
, -1, DNS_DECOMPRESS_ANY
);
1105 result
= dns_rdata_fromwire(&rdata
, class, type
, &wbuf
,
1107 dns_decompress_invalidate(&dctx
);
1108 if (result
!= ISC_R_SUCCESS
) {
1110 "dns_rdata_fromwire returned %s(%d)\n",
1111 dns_result_totext(result
), result
);
1118 fputs("\n", stdout
);
1119 for (i
= 0; i
< rdata
.length
; /* */ ) {
1120 fprintf(stdout
, "%02x", rdata
.data
[i
]);
1121 if ((++i
% 20) == 0)
1122 fputs("\n", stdout
);
1124 if (i
== rdata
.length
)
1125 fputs("\n", stdout
);
1131 isc_mem_t
*mctx2
= NULL
;
1132 dns_rdata_t rdata2
= DNS_RDATA_INIT
;
1135 RUNTIME_CHECK(isc_mem_create(0, 0, &mctx2
)
1138 isc_buffer_init(&vbuf
, viabuf
, sizeof(viabuf
));
1139 dns_rdata_init(&rdata2
);
1140 viastruct(&rdata
, mctx2
, &rdata2
, &vbuf
);
1141 if (!quiet
&& stats
)
1142 isc_mem_stats(mctx2
, stdout
);
1143 isc_mem_destroy(&mctx2
);
1146 isc_buffer_init(&tbuf
, outbuf
, sizeof(outbuf
));
1147 result
= dns_rdata_totext(&rdata
, NULL
, &tbuf
);
1148 if (result
!= ISC_R_SUCCESS
)
1149 fprintf(stdout
, "dns_rdata_totext returned %s(%d)\n",
1150 dns_result_totext(result
), result
);
1152 fprintf(stdout
, "\"%.*s\"\n",
1153 (int)tbuf
.used
, (char*)tbuf
.base
);
1155 if (lasttype
== type
) {
1156 fprintf(stdout
, "dns_rdata_compare = %d\n",
1157 dns_rdata_compare(&rdata
, &last
));
1163 dns_rdata_init(&last
);
1164 region
.base
= malloc(region
.length
= rdata
.length
);
1166 memcpy(region
.base
, rdata
.data
, rdata
.length
);
1167 dns_rdata_fromregion(&last
, class, type
, ®ion
);
1174 if (result
!= ISC_R_EOF
)
1175 printf("Result: %s\n", isc_result_totext(result
));
1178 isc_lex_destroy(&lex
);
1179 if (!quiet
&& stats
)
1180 isc_mem_stats(mctx
, stdout
);
1181 isc_mem_destroy(&mctx
);