1 /* $NetBSD: rdata_test.c,v 1.8 2014/12/10 04:37:53 christos Exp $ */
4 * Copyright (C) 2004-2007, 2011, 2012, 2014 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.
24 #include <isc/buffer.h>
25 #include <isc/commandline.h>
28 #include <isc/string.h>
31 #include <dns/rdata.h>
32 #include <dns/compress.h>
33 #include <dns/rdataclass.h>
34 #include <dns/rdatastruct.h>
35 #include <dns/rdatatype.h>
36 #include <dns/result.h>
41 isc_lexspecials_t specials
;
44 viastruct(dns_rdata_t
*rdata
, isc_mem_t
*mctx
,
45 dns_rdata_t
*rdata2
, isc_buffer_t
*b
)
49 isc_boolean_t need_free
= ISC_FALSE
;
53 UNUSED(rdata2
); /* XXXMPA remove when fromstruct is ready. */
56 switch (rdata
->type
) {
57 case dns_rdatatype_a6
: {
58 static dns_rdata_in_a6_t in_a6
;
59 result
= dns_rdata_tostruct(rdata
, sp
= &in_a6
, NULL
);
62 case dns_rdatatype_a
: {
63 switch (rdata
->rdclass
) {
64 case dns_rdataclass_hs
: {
65 static dns_rdata_hs_a_t hs_a
;
66 result
= dns_rdata_tostruct(rdata
, sp
= &hs_a
, NULL
);
69 case dns_rdataclass_in
: {
70 static dns_rdata_in_a_t in_a
;
71 result
= dns_rdata_tostruct(rdata
, sp
= &in_a
, NULL
);
75 result
= ISC_R_NOTIMPLEMENTED
;
80 case dns_rdatatype_aaaa
: {
81 static dns_rdata_in_aaaa_t in_aaaa
;
82 result
= dns_rdata_tostruct(rdata
, sp
= &in_aaaa
, NULL
);
85 case dns_rdatatype_afsdb
: {
86 static dns_rdata_afsdb_t afsdb
;
87 result
= dns_rdata_tostruct(rdata
, sp
= &afsdb
, NULL
);
90 case dns_rdatatype_any
: {
91 result
= ISC_R_NOTIMPLEMENTED
;
94 case dns_rdatatype_apl
: {
95 switch (rdata
->rdclass
) {
96 case dns_rdataclass_in
: {
97 static dns_rdata_in_apl_t in_apl
;
98 result
= dns_rdata_tostruct(rdata
, sp
= &in_apl
, NULL
);
102 result
= ISC_R_NOTIMPLEMENTED
;
107 case dns_rdatatype_cert
: {
108 static dns_rdata_cert_t cert
;
109 result
= dns_rdata_tostruct(rdata
, sp
= &cert
, NULL
);
112 case dns_rdatatype_cname
: {
113 static dns_rdata_cname_t cname
;
114 result
= dns_rdata_tostruct(rdata
, sp
= &cname
, NULL
);
117 case dns_rdatatype_dname
: {
118 static dns_rdata_dname_t dname
;
119 result
= dns_rdata_tostruct(rdata
, sp
= &dname
, NULL
);
122 case dns_rdatatype_gpos
: {
123 static dns_rdata_gpos_t gpos
;
124 result
= dns_rdata_tostruct(rdata
, sp
= &gpos
, NULL
);
127 case dns_rdatatype_hinfo
: {
128 static dns_rdata_hinfo_t hinfo
;
129 result
= dns_rdata_tostruct(rdata
, sp
= &hinfo
, NULL
);
132 case dns_rdatatype_isdn
: {
133 static dns_rdata_isdn_t isdn
;
134 result
= dns_rdata_tostruct(rdata
, sp
= &isdn
, NULL
);
137 case dns_rdatatype_key
: {
138 static dns_rdata_key_t key
;
139 result
= dns_rdata_tostruct(rdata
, sp
= &key
, NULL
);
142 case dns_rdatatype_kx
: {
143 static dns_rdata_in_kx_t in_kx
;
144 result
= dns_rdata_tostruct(rdata
, sp
= &in_kx
, NULL
);
147 case dns_rdatatype_loc
: {
148 static dns_rdata_loc_t loc
;
149 result
= dns_rdata_tostruct(rdata
, sp
= &loc
, NULL
);
152 case dns_rdatatype_mb
: {
153 static dns_rdata_mb_t mb
;
154 result
= dns_rdata_tostruct(rdata
, sp
= &mb
, NULL
);
157 case dns_rdatatype_md
: {
158 static dns_rdata_md_t md
;
159 result
= dns_rdata_tostruct(rdata
, sp
= &md
, NULL
);
162 case dns_rdatatype_mf
: {
163 static dns_rdata_mf_t mf
;
164 result
= dns_rdata_tostruct(rdata
, sp
= &mf
, NULL
);
167 case dns_rdatatype_mg
: {
168 static dns_rdata_mg_t mg
;
169 result
= dns_rdata_tostruct(rdata
, sp
= &mg
, NULL
);
172 case dns_rdatatype_minfo
: {
173 static dns_rdata_minfo_t minfo
;
174 result
= dns_rdata_tostruct(rdata
, sp
= &minfo
, NULL
);
177 case dns_rdatatype_mr
: {
178 static dns_rdata_mr_t mr
;
179 result
= dns_rdata_tostruct(rdata
, sp
= &mr
, NULL
);
182 case dns_rdatatype_mx
: {
183 static dns_rdata_mx_t mx
;
184 result
= dns_rdata_tostruct(rdata
, sp
= &mx
, NULL
);
187 case dns_rdatatype_naptr
: {
188 static dns_rdata_naptr_t naptr
;
189 result
= dns_rdata_tostruct(rdata
, sp
= &naptr
, NULL
);
192 case dns_rdatatype_ns
: {
193 static dns_rdata_ns_t ns
;
194 result
= dns_rdata_tostruct(rdata
, sp
= &ns
, NULL
);
197 case dns_rdatatype_nsap
: {
198 static dns_rdata_in_nsap_t in_nsap
;
199 result
= dns_rdata_tostruct(rdata
, sp
= &in_nsap
, NULL
);
202 case dns_rdatatype_nsap_ptr
: {
203 static dns_rdata_in_nsap_ptr_t in_nsap_ptr
;
204 result
= dns_rdata_tostruct(rdata
, sp
= &in_nsap_ptr
, NULL
);
207 case dns_rdatatype_null
: {
208 static dns_rdata_null_t null
;
209 result
= dns_rdata_tostruct(rdata
, sp
= &null
, NULL
);
212 case dns_rdatatype_nxt
: {
213 static dns_rdata_nxt_t nxt
;
214 result
= dns_rdata_tostruct(rdata
, sp
= &nxt
, NULL
);
217 case dns_rdatatype_opt
: {
218 static dns_rdata_opt_t opt
;
219 result
= dns_rdata_tostruct(rdata
, sp
= &opt
, NULL
);
222 case dns_rdatatype_ptr
: {
223 static dns_rdata_ptr_t ptr
;
224 result
= dns_rdata_tostruct(rdata
, sp
= &ptr
, NULL
);
227 case dns_rdatatype_px
: {
228 static dns_rdata_in_px_t in_px
;
229 result
= dns_rdata_tostruct(rdata
, sp
= &in_px
, NULL
);
232 case dns_rdatatype_rp
: {
233 static dns_rdata_rp_t rp
;
234 result
= dns_rdata_tostruct(rdata
, sp
= &rp
, NULL
);
237 case dns_rdatatype_rt
: {
238 static dns_rdata_rt_t rt
;
239 result
= dns_rdata_tostruct(rdata
, sp
= &rt
, NULL
);
242 case dns_rdatatype_sig
: {
243 static dns_rdata_sig_t sig
;
244 result
= dns_rdata_tostruct(rdata
, sp
= &sig
, NULL
);
247 case dns_rdatatype_soa
: {
248 static dns_rdata_soa_t soa
;
249 result
= dns_rdata_tostruct(rdata
, sp
= &soa
, NULL
);
252 case dns_rdatatype_srv
: {
253 static dns_rdata_in_srv_t in_srv
;
254 result
= dns_rdata_tostruct(rdata
, sp
= &in_srv
, NULL
);
257 case dns_rdatatype_tkey
: {
258 static dns_rdata_tkey_t tkey
;
259 result
= dns_rdata_tostruct(rdata
, sp
= &tkey
, NULL
);
262 case dns_rdatatype_tsig
: {
263 static dns_rdata_any_tsig_t tsig
;
264 result
= dns_rdata_tostruct(rdata
, sp
= &tsig
, NULL
);
267 case dns_rdatatype_txt
: {
268 static dns_rdata_txt_t txt
;
269 result
= dns_rdata_tostruct(rdata
, sp
= &txt
, NULL
);
272 case dns_rdatatype_spf
: {
273 static dns_rdata_spf_t spf
;
274 result
= dns_rdata_tostruct(rdata
, sp
= &spf
, NULL
);
277 case dns_rdatatype_unspec
: {
278 static dns_rdata_unspec_t unspec
;
279 result
= dns_rdata_tostruct(rdata
, sp
= &unspec
, NULL
);
282 case dns_rdatatype_uri
: {
283 static dns_rdata_uri_t uri
;
284 result
= dns_rdata_tostruct(rdata
, sp
= &uri
, NULL
);
287 case dns_rdatatype_caa
: {
288 static dns_rdata_caa_t caa
;
289 result
= dns_rdata_tostruct(rdata
, sp
= &caa
, NULL
);
292 case dns_rdatatype_wks
: {
293 static dns_rdata_in_wks_t in_wks
;
294 result
= dns_rdata_tostruct(rdata
, sp
= &in_wks
, NULL
);
297 case dns_rdatatype_x25
: {
298 static dns_rdata_x25_t x25
;
299 result
= dns_rdata_tostruct(rdata
, sp
= &x25
, NULL
);
302 case dns_rdatatype_nsec
: {
303 static dns_rdata_nsec_t nsec
;
304 result
= dns_rdata_tostruct(rdata
, sp
= &nsec
, NULL
);
307 case dns_rdatatype_rrsig
: {
308 static dns_rdata_rrsig_t rrsig
;
309 result
= dns_rdata_tostruct(rdata
, sp
= &rrsig
, NULL
);
312 case dns_rdatatype_dnskey
: {
313 static dns_rdata_dnskey_t dnskey
;
314 result
= dns_rdata_tostruct(rdata
, sp
= &dnskey
, NULL
);
318 result
= ISC_R_NOTIMPLEMENTED
;
321 if (result
!= ISC_R_SUCCESS
)
322 fprintf(stdout
, "viastruct: tostruct %d %d return %s\n",
323 rdata
->type
, rdata
->rdclass
,
324 dns_result_totext(result
));
326 dns_rdata_freestruct(sp
);
328 switch (rdata
->type
) {
329 case dns_rdatatype_a6
: {
330 static dns_rdata_in_a6_t in_a6
;
331 result
= dns_rdata_tostruct(rdata
, sp
= &in_a6
, mctx
);
334 case dns_rdatatype_a
: {
335 switch (rdata
->rdclass
) {
336 case dns_rdataclass_hs
: {
337 static dns_rdata_hs_a_t hs_a
;
338 result
= dns_rdata_tostruct(rdata
, sp
= &hs_a
, mctx
);
341 case dns_rdataclass_in
: {
342 static dns_rdata_in_a_t in_a
;
343 result
= dns_rdata_tostruct(rdata
, sp
= &in_a
, mctx
);
347 result
= ISC_R_NOTIMPLEMENTED
;
352 case dns_rdatatype_aaaa
: {
353 static dns_rdata_in_aaaa_t in_aaaa
;
354 result
= dns_rdata_tostruct(rdata
, sp
= &in_aaaa
, mctx
);
357 case dns_rdatatype_afsdb
: {
358 static dns_rdata_afsdb_t afsdb
;
359 result
= dns_rdata_tostruct(rdata
, sp
= &afsdb
, mctx
);
362 case dns_rdatatype_any
: {
363 result
= ISC_R_NOTIMPLEMENTED
;
366 case dns_rdatatype_apl
: {
367 switch (rdata
->rdclass
) {
368 case dns_rdataclass_in
: {
369 static dns_rdata_in_apl_t in_apl
;
370 result
= dns_rdata_tostruct(rdata
, sp
= &in_apl
, mctx
);
374 result
= ISC_R_NOTIMPLEMENTED
;
379 case dns_rdatatype_cert
: {
380 static dns_rdata_cert_t cert
;
381 result
= dns_rdata_tostruct(rdata
, sp
= &cert
, mctx
);
384 case dns_rdatatype_cname
: {
385 static dns_rdata_cname_t cname
;
386 result
= dns_rdata_tostruct(rdata
, sp
= &cname
, mctx
);
389 case dns_rdatatype_dname
: {
390 static dns_rdata_dname_t dname
;
391 result
= dns_rdata_tostruct(rdata
, sp
= &dname
, mctx
);
394 case dns_rdatatype_gpos
: {
395 static dns_rdata_gpos_t gpos
;
396 result
= dns_rdata_tostruct(rdata
, sp
= &gpos
, mctx
);
399 case dns_rdatatype_hinfo
: {
400 static dns_rdata_hinfo_t hinfo
;
401 result
= dns_rdata_tostruct(rdata
, sp
= &hinfo
, mctx
);
404 case dns_rdatatype_isdn
: {
405 static dns_rdata_isdn_t isdn
;
406 result
= dns_rdata_tostruct(rdata
, sp
= &isdn
, mctx
);
409 case dns_rdatatype_key
: {
410 static dns_rdata_key_t key
;
411 result
= dns_rdata_tostruct(rdata
, sp
= &key
, mctx
);
414 case dns_rdatatype_kx
: {
415 static dns_rdata_in_kx_t in_kx
;
416 result
= dns_rdata_tostruct(rdata
, sp
= &in_kx
, mctx
);
419 case dns_rdatatype_loc
: {
420 static dns_rdata_loc_t loc
;
421 result
= dns_rdata_tostruct(rdata
, sp
= &loc
, mctx
);
424 case dns_rdatatype_mb
: {
425 static dns_rdata_mb_t mb
;
426 result
= dns_rdata_tostruct(rdata
, sp
= &mb
, mctx
);
429 case dns_rdatatype_md
: {
430 static dns_rdata_md_t md
;
431 result
= dns_rdata_tostruct(rdata
, sp
= &md
, mctx
);
434 case dns_rdatatype_mf
: {
435 static dns_rdata_mf_t mf
;
436 result
= dns_rdata_tostruct(rdata
, sp
= &mf
, mctx
);
439 case dns_rdatatype_mg
: {
440 static dns_rdata_mg_t mg
;
441 result
= dns_rdata_tostruct(rdata
, sp
= &mg
, mctx
);
444 case dns_rdatatype_minfo
: {
445 static dns_rdata_minfo_t minfo
;
446 result
= dns_rdata_tostruct(rdata
, sp
= &minfo
, mctx
);
449 case dns_rdatatype_mr
: {
450 static dns_rdata_mr_t mr
;
451 result
= dns_rdata_tostruct(rdata
, sp
= &mr
, mctx
);
454 case dns_rdatatype_mx
: {
455 static dns_rdata_mx_t mx
;
456 result
= dns_rdata_tostruct(rdata
, sp
= &mx
, mctx
);
459 case dns_rdatatype_naptr
: {
460 static dns_rdata_naptr_t naptr
;
461 result
= dns_rdata_tostruct(rdata
, sp
= &naptr
, mctx
);
464 case dns_rdatatype_ns
: {
465 static dns_rdata_ns_t ns
;
466 result
= dns_rdata_tostruct(rdata
, sp
= &ns
, mctx
);
469 case dns_rdatatype_nsap
: {
470 static dns_rdata_in_nsap_t in_nsap
;
471 result
= dns_rdata_tostruct(rdata
, sp
= &in_nsap
, mctx
);
474 case dns_rdatatype_nsap_ptr
: {
475 static dns_rdata_in_nsap_ptr_t in_nsap_ptr
;
476 result
= dns_rdata_tostruct(rdata
, sp
= &in_nsap_ptr
, mctx
);
479 case dns_rdatatype_null
: {
480 static dns_rdata_null_t null
;
481 result
= dns_rdata_tostruct(rdata
, sp
= &null
, mctx
);
484 case dns_rdatatype_nxt
: {
485 static dns_rdata_nxt_t nxt
;
486 result
= dns_rdata_tostruct(rdata
, sp
= &nxt
, mctx
);
489 case dns_rdatatype_opt
: {
490 static dns_rdata_opt_t opt
;
491 result
= dns_rdata_tostruct(rdata
, sp
= &opt
, mctx
);
494 case dns_rdatatype_ptr
: {
495 static dns_rdata_ptr_t ptr
;
496 result
= dns_rdata_tostruct(rdata
, sp
= &ptr
, mctx
);
499 case dns_rdatatype_px
: {
500 static dns_rdata_in_px_t in_px
;
501 result
= dns_rdata_tostruct(rdata
, sp
= &in_px
, mctx
);
504 case dns_rdatatype_rp
: {
505 static dns_rdata_rp_t rp
;
506 result
= dns_rdata_tostruct(rdata
, sp
= &rp
, mctx
);
509 case dns_rdatatype_rt
: {
510 static dns_rdata_rt_t rt
;
511 result
= dns_rdata_tostruct(rdata
, sp
= &rt
, mctx
);
514 case dns_rdatatype_sig
: {
515 static dns_rdata_sig_t sig
;
516 result
= dns_rdata_tostruct(rdata
, sp
= &sig
, mctx
);
519 case dns_rdatatype_soa
: {
520 static dns_rdata_soa_t soa
;
521 result
= dns_rdata_tostruct(rdata
, sp
= &soa
, mctx
);
524 case dns_rdatatype_srv
: {
525 static dns_rdata_in_srv_t in_srv
;
526 result
= dns_rdata_tostruct(rdata
, sp
= &in_srv
, mctx
);
529 case dns_rdatatype_tkey
: {
530 static dns_rdata_tkey_t tkey
;
531 result
= dns_rdata_tostruct(rdata
, sp
= &tkey
, mctx
);
534 case dns_rdatatype_tsig
: {
535 static dns_rdata_any_tsig_t tsig
;
536 result
= dns_rdata_tostruct(rdata
, sp
= &tsig
, mctx
);
539 case dns_rdatatype_txt
: {
540 static dns_rdata_txt_t txt
;
541 result
= dns_rdata_tostruct(rdata
, sp
= &txt
, mctx
);
544 case dns_rdatatype_spf
: {
545 static dns_rdata_spf_t spf
;
546 result
= dns_rdata_tostruct(rdata
, sp
= &spf
, mctx
);
549 case dns_rdatatype_unspec
: {
550 static dns_rdata_unspec_t unspec
;
551 result
= dns_rdata_tostruct(rdata
, sp
= &unspec
, mctx
);
554 case dns_rdatatype_uri
: {
555 static dns_rdata_uri_t uri
;
556 result
= dns_rdata_tostruct(rdata
, sp
= &uri
, mctx
);
559 case dns_rdatatype_caa
: {
560 static dns_rdata_caa_t caa
;
561 result
= dns_rdata_tostruct(rdata
, sp
= &caa
, mctx
);
564 case dns_rdatatype_wks
: {
565 static dns_rdata_in_wks_t in_wks
;
566 result
= dns_rdata_tostruct(rdata
, sp
= &in_wks
, mctx
);
569 case dns_rdatatype_x25
: {
570 static dns_rdata_x25_t x25
;
571 result
= dns_rdata_tostruct(rdata
, sp
= &x25
, mctx
);
574 case dns_rdatatype_nsec
: {
575 static dns_rdata_nsec_t nsec
;
576 result
= dns_rdata_tostruct(rdata
, sp
= &nsec
, mctx
);
579 case dns_rdatatype_rrsig
: {
580 static dns_rdata_rrsig_t rrsig
;
581 result
= dns_rdata_tostruct(rdata
, sp
= &rrsig
, mctx
);
584 case dns_rdatatype_dnskey
: {
585 static dns_rdata_dnskey_t dnskey
;
586 result
= dns_rdata_tostruct(rdata
, sp
= &dnskey
, mctx
);
590 result
= ISC_R_NOTIMPLEMENTED
;
593 if (result
!= ISC_R_SUCCESS
)
594 fprintf(stdout
, "viastruct: tostruct %d %d return %s\n",
595 rdata
->type
, rdata
->rdclass
,
596 dns_result_totext(result
));
598 need_free
= ISC_TRUE
;
600 rdc
= rdata
->rdclass
;
602 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, sp
, b
);
603 if (result
!= ISC_R_SUCCESS
)
605 "viastruct: fromstruct %d %d return %s\n",
606 rdata
->type
, rdata
->rdclass
,
607 dns_result_totext(result
));
608 else if (rdata
->length
!= rdata2
->length
||
609 memcmp(rdata
->data
, rdata2
->data
, rdata
->length
) != 0)
614 fprintf(stdout
, "viastruct: memcmp failed\n");
616 fprintf(stdout
, "%d %d\n",
617 rdata
->length
, rdata2
->length
);
619 if (rdata2
->length
< l
)
621 for (i
= 0; i
< l
; i
++)
622 fprintf(stdout
, "%02x %02x\n",
623 rdata
->data
[i
], rdata2
->data
[i
]);
627 switch (rdata
->type
) {
628 case dns_rdatatype_a6
: {
629 dns_rdata_in_a6_t in_a6
;
630 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_a6
, b
);
633 case dns_rdatatype_a
: {
634 switch (rdata
->rdclass
) {
635 case dns_rdataclass_hs
: {
636 dns_rdata_hs_a_t hs_a
;
637 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
,
641 case dns_rdataclass_in
: {
642 dns_rdata_in_a_t in_a
;
643 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
,
648 result
= ISC_R_NOTIMPLEMENTED
;
653 case dns_rdatatype_aaaa
: {
654 dns_rdata_in_aaaa_t in_aaaa
;
655 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_aaaa
, b
);
658 case dns_rdatatype_afsdb
: {
659 dns_rdata_afsdb_t afsdb
;
660 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &afsdb
, b
);
663 case dns_rdatatype_any
: {
664 result
= ISC_R_NOTIMPLEMENTED
;
667 case dns_rdatatype_apl
: {
668 switch (rdata
->rdclass
) {
669 case dns_rdataclass_in
: {
670 dns_rdata_in_apl_t in_apl
;
671 result
= dns_rdata_fromstruct(rdata
, rdc
, rdt
, &in_apl
, b
);
675 result
= ISC_R_NOTIMPLEMENTED
;
680 case dns_rdatatype_cert
: {
681 dns_rdata_cert_t cert
;
682 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &cert
, b
);
685 case dns_rdatatype_cname
: {
686 dns_rdata_cname_t cname
;
687 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &cname
, b
);
690 case dns_rdatatype_dname
: {
691 dns_rdata_dname_t dname
;
692 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &dname
, b
);
695 case dns_rdatatype_gpos
: {
696 dns_rdata_gpos_t gpos
;
697 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &gpos
, b
);
700 case dns_rdatatype_hinfo
: {
701 dns_rdata_hinfo_t hinfo
;
702 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &hinfo
, b
);
705 case dns_rdatatype_isdn
: {
706 dns_rdata_isdn_t isdn
;
707 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &isdn
, b
);
710 case dns_rdatatype_key
: {
712 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &key
, b
);
715 case dns_rdatatype_kx
: {
716 dns_rdata_in_kx_t in_kx
;
717 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_kx
, b
);
720 case dns_rdatatype_loc
: {
722 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &loc
, b
);
725 case dns_rdatatype_mb
: {
727 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &mb
, b
);
730 case dns_rdatatype_md
: {
732 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &md
, b
);
735 case dns_rdatatype_mf
: {
737 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &mf
, b
);
740 case dns_rdatatype_mg
: {
742 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &mg
, b
);
745 case dns_rdatatype_minfo
: {
746 dns_rdata_minfo_t minfo
;
747 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &minfo
, b
);
750 case dns_rdatatype_mr
: {
752 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &mr
, b
);
755 case dns_rdatatype_mx
: {
757 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &mx
, b
);
760 case dns_rdatatype_naptr
: {
761 dns_rdata_naptr_t naptr
;
762 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &naptr
, b
);
765 case dns_rdatatype_ns
: {
767 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &ns
, b
);
770 case dns_rdatatype_nsap
: {
771 dns_rdata_in_nsap_t in_nsap
;
772 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_nsap
, b
);
775 case dns_rdatatype_nsap_ptr
: {
776 dns_rdata_in_nsap_ptr_t in_nsap_ptr
;
777 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_nsap_ptr
,
781 case dns_rdatatype_null
: {
782 dns_rdata_null_t null
;
783 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &null
, b
);
786 case dns_rdatatype_nxt
: {
788 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &nxt
, b
);
791 case dns_rdatatype_opt
: {
793 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &opt
, b
);
796 case dns_rdatatype_ptr
: {
798 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &ptr
, b
);
801 case dns_rdatatype_px
: {
802 dns_rdata_in_px_t in_px
;
803 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_px
, b
);
806 case dns_rdatatype_rp
: {
808 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &rp
, b
);
811 case dns_rdatatype_rt
: {
813 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &rt
, b
);
816 case dns_rdatatype_sig
: {
818 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &sig
, b
);
821 case dns_rdatatype_soa
: {
823 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &soa
, b
);
826 case dns_rdatatype_srv
: {
827 dns_rdata_in_srv_t in_srv
;
828 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_srv
, b
);
831 case dns_rdatatype_tkey
: {
832 dns_rdata_tkey_t tkey
;
833 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &tkey
, b
);
836 case dns_rdatatype_tsig
: {
837 dns_rdata_any_tsig_t tsig
;
838 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &tsig
, b
);
841 case dns_rdatatype_txt
: {
843 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &txt
, b
);
846 case dns_rdatatype_spf
: {
848 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &spf
, b
);
851 case dns_rdatatype_unspec
: {
852 dns_rdata_unspec_t unspec
;
853 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &unspec
, b
);
856 case dns_rdatatype_uri
: {
858 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &uri
, b
);
861 case dns_rdatatype_caa
: {
863 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &caa
, b
);
866 case dns_rdatatype_wks
: {
867 dns_rdata_in_wks_t in_wks
;
868 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &in_wks
, b
);
871 case dns_rdatatype_x25
: {
873 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &x25
, b
);
876 case dns_rdatatype_nsec
: {
877 dns_rdata_nsec_t nsec
;
878 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &nsec
, b
);
881 case dns_rdatatype_rrsig
: {
882 dns_rdata_rrsig_t rrsig
;
883 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &rrsig
, b
);
886 case dns_rdatatype_dnskey
: {
887 dns_rdata_dnskey_t dnskey
;
888 result
= dns_rdata_fromstruct(rdata2
, rdc
, rdt
, &dnskey
, b
);
892 result
= ISC_R_NOTIMPLEMENTED
;
897 dns_rdata_freestruct(sp
);
901 main(int argc
, char *argv
[]) {
907 unsigned int options
= 0;
908 dns_rdatatype_t type
;
909 dns_rdataclass_t
class;
910 dns_rdatatype_t lasttype
= 0;
911 char outbuf
[16*1024];
913 char wirebuf
[16*1024];
914 char viabuf
[16*1024];
918 dns_rdata_t rdata
= DNS_RDATA_INIT
;
919 dns_rdata_t last
= DNS_RDATA_INIT
;
923 dns_decompress_t dctx
;
934 while ((c
= isc_commandline_parse(argc
, argv
, "dqswtarzS")) != -1) {
968 memset(&dctx
, 0, sizeof(dctx
));
969 dctx
.allowed
= DNS_COMPRESS_ALL
;
971 RUNTIME_CHECK(isc_mem_create(0, 0, &mctx
) == ISC_R_SUCCESS
);
972 RUNTIME_CHECK(isc_lex_create(mctx
, 256, &lex
) == ISC_R_SUCCESS
);
975 * Set up to lex DNS master file.
981 isc_lex_setspecials(lex
, specials
);
982 options
= ISC_LEXOPT_EOL
;
983 isc_lex_setcomments(lex
, ISC_LEXCOMMENT_DNSMASTERFILE
);
985 RUNTIME_CHECK(isc_lex_openstream(lex
, stdin
) == ISC_R_SUCCESS
);
987 dns_rdata_init(&last
);
988 while ((result
= isc_lex_gettoken(lex
, options
| ISC_LEXOPT_NUMBER
,
989 &token
)) == ISC_R_SUCCESS
) {
990 if (debug
) fprintf(stdout
, "token.type = %d\n", token
.type
);
992 if (token
.type
== isc_tokentype_eol
)
996 if (token
.type
== isc_tokentype_eof
)
1002 if (token
.type
== isc_tokentype_number
) {
1003 type
= token
.value
.as_ulong
;
1004 isc_buffer_init(&tbuf
, outbuf
, sizeof(outbuf
));
1005 result
= dns_rdatatype_totext(type
, &tbuf
);
1006 if (result
!= ISC_R_SUCCESS
) {
1008 "dns_rdatatype_totext "
1009 "returned %s(%d)\n",
1010 dns_result_totext(result
), result
);
1015 fprintf(stdout
, "type = %.*s(%d)\n",
1016 (int)tbuf
.used
, (char*)tbuf
.base
, type
);
1017 } else if (token
.type
== isc_tokentype_string
) {
1018 result
= dns_rdatatype_fromtext(&type
,
1019 &token
.value
.as_textregion
);
1020 if (result
!= ISC_R_SUCCESS
) {
1022 "dns_rdatatype_fromtext "
1023 "returned %s(%d)\n",
1024 dns_result_totext(result
), result
);
1029 fprintf(stdout
, "type = %.*s(%d)\n",
1030 (int)token
.value
.as_textregion
.length
,
1031 token
.value
.as_textregion
.base
, type
);
1035 result
= isc_lex_gettoken(lex
, options
| ISC_LEXOPT_NUMBER
,
1037 if (result
!= ISC_R_SUCCESS
)
1039 if (token
.type
== isc_tokentype_eol
)
1041 if (token
.type
== isc_tokentype_eof
)
1043 if (token
.type
== isc_tokentype_number
) {
1044 class = token
.value
.as_ulong
;
1045 isc_buffer_init(&tbuf
, outbuf
, sizeof(outbuf
));
1046 result
= dns_rdatatype_totext(class, &tbuf
);
1047 if (result
!= ISC_R_SUCCESS
) {
1048 fprintf(stdout
, "dns_rdatatype_totext "
1049 "returned %s(%d)\n",
1050 dns_result_totext(result
), result
);
1055 fprintf(stdout
, "class = %.*s(%d)\n",
1056 (int)tbuf
.used
, (char*)tbuf
.base
, class);
1057 } else if (token
.type
== isc_tokentype_string
) {
1058 result
= dns_rdataclass_fromtext(&class,
1059 &token
.value
.as_textregion
);
1060 if (result
!= ISC_R_SUCCESS
) {
1061 fprintf(stdout
, "dns_rdataclass_fromtext "
1062 "returned %s(%d)\n",
1063 dns_result_totext(result
), result
);
1068 fprintf(stdout
, "class = %.*s(%d)\n",
1069 (int)token
.value
.as_textregion
.length
,
1070 token
.value
.as_textregion
.base
, class);
1075 dns_rdata_init(&rdata
);
1076 isc_buffer_init(&dbuf
, inbuf
, sizeof(inbuf
));
1077 result
= dns_rdata_fromtext(&rdata
, class, type
, lex
,
1078 NULL
, 0, mctx
, &dbuf
,
1080 if (result
!= ISC_R_SUCCESS
) {
1082 "dns_rdata_fromtext returned %s(%d)\n",
1083 dns_result_totext(result
), result
);
1089 for (i
= 0; i
< rdata
.length
; /* */ ) {
1090 fprintf(stdout
, "%02x", rdata
.data
[i
]);
1091 if ((++i
% 20) == 0)
1092 fputs("\n", stdout
);
1094 if (i
== rdata
.length
)
1095 fputs("\n", stdout
);
1102 * Convert to wire and back?
1105 result
= dns_compress_init(&cctx
, -1, mctx
);
1106 if (result
!= ISC_R_SUCCESS
) {
1108 "dns_compress_init returned %s(%d)\n",
1109 dns_result_totext(result
), result
);
1112 isc_buffer_init(&wbuf
, wirebuf
, sizeof(wirebuf
));
1113 result
= dns_rdata_towire(&rdata
, &cctx
, &wbuf
);
1114 dns_compress_invalidate(&cctx
);
1115 if (result
!= ISC_R_SUCCESS
) {
1117 "dns_rdata_towire returned %s(%d)\n",
1118 dns_result_totext(result
), result
);
1121 len
= wbuf
.used
- wbuf
.current
;
1124 fputs("\n", stdout
);
1125 for (i
= 0; i
< (unsigned int)len
; /* */ ) {
1126 fprintf(stdout
, "%02x",
1127 ((unsigned char*)wbuf
.base
)[i
+ wbuf
.current
]);
1128 if ((++i
% 20) == 0)
1129 fputs("\n", stdout
);
1132 fputs("\n", stdout
);
1140 len
= (len
* 3) / 4;
1142 isc_buffer_add(&wbuf
, len
/ 4 + 1);
1146 isc_buffer_setactive(&wbuf
, len
);
1147 dns_rdata_init(&rdata
);
1148 isc_buffer_init(&dbuf
, inbuf
, sizeof(inbuf
));
1149 dns_decompress_init(&dctx
, -1, DNS_DECOMPRESS_ANY
);
1150 result
= dns_rdata_fromwire(&rdata
, class, type
, &wbuf
,
1152 dns_decompress_invalidate(&dctx
);
1153 if (result
!= ISC_R_SUCCESS
) {
1155 "dns_rdata_fromwire returned %s(%d)\n",
1156 dns_result_totext(result
), result
);
1163 fputs("\n", stdout
);
1164 for (i
= 0; i
< rdata
.length
; /* */ ) {
1165 fprintf(stdout
, "%02x", rdata
.data
[i
]);
1166 if ((++i
% 20) == 0)
1167 fputs("\n", stdout
);
1169 if (i
== rdata
.length
)
1170 fputs("\n", stdout
);
1176 isc_mem_t
*mctx2
= NULL
;
1177 dns_rdata_t rdata2
= DNS_RDATA_INIT
;
1180 RUNTIME_CHECK(isc_mem_create(0, 0, &mctx2
)
1183 isc_buffer_init(&vbuf
, viabuf
, sizeof(viabuf
));
1184 dns_rdata_init(&rdata2
);
1185 viastruct(&rdata
, mctx2
, &rdata2
, &vbuf
);
1186 if (!quiet
&& stats
)
1187 isc_mem_stats(mctx2
, stdout
);
1188 isc_mem_destroy(&mctx2
);
1191 isc_buffer_init(&tbuf
, outbuf
, sizeof(outbuf
));
1192 result
= dns_rdata_totext(&rdata
, NULL
, &tbuf
);
1193 if (result
!= ISC_R_SUCCESS
)
1194 fprintf(stdout
, "dns_rdata_totext returned %s(%d)\n",
1195 dns_result_totext(result
), result
);
1197 fprintf(stdout
, "\"%.*s\"\n",
1198 (int)tbuf
.used
, (char*)tbuf
.base
);
1200 if (lasttype
== type
) {
1201 fprintf(stdout
, "dns_rdata_compare = %d\n",
1202 dns_rdata_compare(&rdata
, &last
));
1208 dns_rdata_init(&last
);
1209 region
.base
= malloc(region
.length
= rdata
.length
);
1211 memmove(region
.base
, rdata
.data
, rdata
.length
);
1212 dns_rdata_fromregion(&last
, class, type
, ®ion
);
1219 if (result
!= ISC_R_EOF
)
1220 printf("Result: %s\n", isc_result_totext(result
));
1223 isc_lex_destroy(&lex
);
1224 if (!quiet
&& stats
)
1225 isc_mem_stats(mctx
, stdout
);
1226 isc_mem_destroy(&mctx
);