No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / bind / dist / bin / tests / rdata_test.c
blobd87b439e8e3b34fcf029af07afdfefb406a3cf58
1 /* $NetBSD$ */
3 /*
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 */
22 #include <config.h>
24 #include <stdlib.h>
26 #include <isc/buffer.h>
27 #include <isc/commandline.h>
28 #include <isc/lex.h>
29 #include <isc/mem.h>
30 #include <isc/string.h>
31 #include <isc/util.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>
40 isc_mem_t *mctx;
41 isc_lex_t *lex;
43 isc_lexspecials_t specials;
45 static void
46 viastruct(dns_rdata_t *rdata, isc_mem_t *mctx,
47 dns_rdata_t *rdata2, isc_buffer_t *b)
49 isc_result_t result;
50 void *sp = NULL;
51 isc_boolean_t need_free = ISC_FALSE;
52 dns_rdatatype_t rdt;
53 dns_rdataclass_t rdc;
55 UNUSED(rdata2); /* XXXMPA remove when fromstruct is ready. */
56 UNUSED(b);
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);
62 break;
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);
69 break;
71 case dns_rdataclass_in: {
72 dns_rdata_in_a_t in_a;
73 result = dns_rdata_tostruct(rdata, sp = &in_a, NULL);
74 break;
76 default:
77 result = ISC_R_NOTIMPLEMENTED;
78 break;
80 break;
82 case dns_rdatatype_aaaa: {
83 dns_rdata_in_aaaa_t in_aaaa;
84 result = dns_rdata_tostruct(rdata, sp = &in_aaaa, NULL);
85 break;
87 case dns_rdatatype_afsdb: {
88 dns_rdata_afsdb_t afsdb;
89 result = dns_rdata_tostruct(rdata, sp = &afsdb, NULL);
90 break;
92 case dns_rdatatype_any: {
93 result = ISC_R_NOTIMPLEMENTED;
94 break;
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);
101 break;
103 default:
104 result = ISC_R_NOTIMPLEMENTED;
105 break;
107 break;
109 case dns_rdatatype_cert: {
110 dns_rdata_cert_t cert;
111 result = dns_rdata_tostruct(rdata, sp = &cert, NULL);
112 break;
114 case dns_rdatatype_cname: {
115 dns_rdata_cname_t cname;
116 result = dns_rdata_tostruct(rdata, sp = &cname, NULL);
117 break;
119 case dns_rdatatype_dname: {
120 dns_rdata_dname_t dname;
121 result = dns_rdata_tostruct(rdata, sp = &dname, NULL);
122 break;
124 case dns_rdatatype_gpos: {
125 dns_rdata_gpos_t gpos;
126 result = dns_rdata_tostruct(rdata, sp = &gpos, NULL);
127 break;
129 case dns_rdatatype_hinfo: {
130 dns_rdata_hinfo_t hinfo;
131 result = dns_rdata_tostruct(rdata, sp = &hinfo, NULL);
132 break;
134 case dns_rdatatype_isdn: {
135 dns_rdata_isdn_t isdn;
136 result = dns_rdata_tostruct(rdata, sp = &isdn, NULL);
137 break;
139 case dns_rdatatype_key: {
140 dns_rdata_key_t key;
141 result = dns_rdata_tostruct(rdata, sp = &key, NULL);
142 break;
144 case dns_rdatatype_kx: {
145 dns_rdata_in_kx_t in_kx;
146 result = dns_rdata_tostruct(rdata, sp = &in_kx, NULL);
147 break;
149 case dns_rdatatype_loc: {
150 dns_rdata_loc_t loc;
151 result = dns_rdata_tostruct(rdata, sp = &loc, NULL);
152 break;
154 case dns_rdatatype_mb: {
155 dns_rdata_mb_t mb;
156 result = dns_rdata_tostruct(rdata, sp = &mb, NULL);
157 break;
159 case dns_rdatatype_md: {
160 dns_rdata_md_t md;
161 result = dns_rdata_tostruct(rdata, sp = &md, NULL);
162 break;
164 case dns_rdatatype_mf: {
165 dns_rdata_mf_t mf;
166 result = dns_rdata_tostruct(rdata, sp = &mf, NULL);
167 break;
169 case dns_rdatatype_mg: {
170 dns_rdata_mg_t mg;
171 result = dns_rdata_tostruct(rdata, sp = &mg, NULL);
172 break;
174 case dns_rdatatype_minfo: {
175 dns_rdata_minfo_t minfo;
176 result = dns_rdata_tostruct(rdata, sp = &minfo, NULL);
177 break;
179 case dns_rdatatype_mr: {
180 dns_rdata_mr_t mr;
181 result = dns_rdata_tostruct(rdata, sp = &mr, NULL);
182 break;
184 case dns_rdatatype_mx: {
185 dns_rdata_mx_t mx;
186 result = dns_rdata_tostruct(rdata, sp = &mx, NULL);
187 break;
189 case dns_rdatatype_naptr: {
190 dns_rdata_in_naptr_t in_naptr;
191 result = dns_rdata_tostruct(rdata, sp = &in_naptr, NULL);
192 break;
194 case dns_rdatatype_ns: {
195 dns_rdata_ns_t ns;
196 result = dns_rdata_tostruct(rdata, sp = &ns, NULL);
197 break;
199 case dns_rdatatype_nsap: {
200 dns_rdata_in_nsap_t in_nsap;
201 result = dns_rdata_tostruct(rdata, sp = &in_nsap, NULL);
202 break;
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);
207 break;
209 case dns_rdatatype_null: {
210 dns_rdata_null_t null;
211 result = dns_rdata_tostruct(rdata, sp = &null, NULL);
212 break;
214 case dns_rdatatype_nxt: {
215 dns_rdata_nxt_t nxt;
216 result = dns_rdata_tostruct(rdata, sp = &nxt, NULL);
217 break;
219 case dns_rdatatype_opt: {
220 dns_rdata_opt_t opt;
221 result = dns_rdata_tostruct(rdata, sp = &opt, NULL);
222 break;
224 case dns_rdatatype_ptr: {
225 dns_rdata_ptr_t ptr;
226 result = dns_rdata_tostruct(rdata, sp = &ptr, NULL);
227 break;
229 case dns_rdatatype_px: {
230 dns_rdata_in_px_t in_px;
231 result = dns_rdata_tostruct(rdata, sp = &in_px, NULL);
232 break;
234 case dns_rdatatype_rp: {
235 dns_rdata_rp_t rp;
236 result = dns_rdata_tostruct(rdata, sp = &rp, NULL);
237 break;
239 case dns_rdatatype_rt: {
240 dns_rdata_rt_t rt;
241 result = dns_rdata_tostruct(rdata, sp = &rt, NULL);
242 break;
244 case dns_rdatatype_sig: {
245 dns_rdata_sig_t sig;
246 result = dns_rdata_tostruct(rdata, sp = &sig, NULL);
247 break;
249 case dns_rdatatype_soa: {
250 dns_rdata_soa_t soa;
251 result = dns_rdata_tostruct(rdata, sp = &soa, NULL);
252 break;
254 case dns_rdatatype_srv: {
255 dns_rdata_in_srv_t in_srv;
256 result = dns_rdata_tostruct(rdata, sp = &in_srv, NULL);
257 break;
259 case dns_rdatatype_tkey: {
260 dns_rdata_tkey_t tkey;
261 result = dns_rdata_tostruct(rdata, sp = &tkey, NULL);
262 break;
264 case dns_rdatatype_tsig: {
265 dns_rdata_any_tsig_t tsig;
266 result = dns_rdata_tostruct(rdata, sp = &tsig, NULL);
267 break;
269 case dns_rdatatype_txt: {
270 dns_rdata_txt_t txt;
271 result = dns_rdata_tostruct(rdata, sp = &txt, NULL);
272 break;
274 case dns_rdatatype_spf: {
275 dns_rdata_spf_t spf;
276 result = dns_rdata_tostruct(rdata, sp = &spf, NULL);
277 break;
279 case dns_rdatatype_unspec: {
280 dns_rdata_unspec_t unspec;
281 result = dns_rdata_tostruct(rdata, sp = &unspec, NULL);
282 break;
284 case dns_rdatatype_wks: {
285 dns_rdata_in_wks_t in_wks;
286 result = dns_rdata_tostruct(rdata, sp = &in_wks, NULL);
287 break;
289 case dns_rdatatype_x25: {
290 dns_rdata_x25_t x25;
291 result = dns_rdata_tostruct(rdata, sp = &x25, NULL);
292 break;
294 case dns_rdatatype_nsec: {
295 dns_rdata_nsec_t nsec;
296 result = dns_rdata_tostruct(rdata, sp = &nsec, NULL);
297 break;
299 case dns_rdatatype_rrsig: {
300 dns_rdata_rrsig_t rrsig;
301 result = dns_rdata_tostruct(rdata, sp = &rrsig, NULL);
302 break;
304 case dns_rdatatype_dnskey: {
305 dns_rdata_dnskey_t dnskey;
306 result = dns_rdata_tostruct(rdata, sp = &dnskey, NULL);
307 break;
309 default:
310 result = ISC_R_NOTIMPLEMENTED;
311 break;
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));
317 else
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);
324 break;
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);
331 break;
333 case dns_rdataclass_in: {
334 dns_rdata_in_a_t in_a;
335 result = dns_rdata_tostruct(rdata, sp = &in_a, mctx);
336 break;
338 default:
339 result = ISC_R_NOTIMPLEMENTED;
340 break;
342 break;
344 case dns_rdatatype_aaaa: {
345 dns_rdata_in_aaaa_t in_aaaa;
346 result = dns_rdata_tostruct(rdata, sp = &in_aaaa, mctx);
347 break;
349 case dns_rdatatype_afsdb: {
350 dns_rdata_afsdb_t afsdb;
351 result = dns_rdata_tostruct(rdata, sp = &afsdb, mctx);
352 break;
354 case dns_rdatatype_any: {
355 result = ISC_R_NOTIMPLEMENTED;
356 break;
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);
363 break;
365 default:
366 result = ISC_R_NOTIMPLEMENTED;
367 break;
369 break;
371 case dns_rdatatype_cert: {
372 dns_rdata_cert_t cert;
373 result = dns_rdata_tostruct(rdata, sp = &cert, mctx);
374 break;
376 case dns_rdatatype_cname: {
377 dns_rdata_cname_t cname;
378 result = dns_rdata_tostruct(rdata, sp = &cname, mctx);
379 break;
381 case dns_rdatatype_dname: {
382 dns_rdata_dname_t dname;
383 result = dns_rdata_tostruct(rdata, sp = &dname, mctx);
384 break;
386 case dns_rdatatype_gpos: {
387 dns_rdata_gpos_t gpos;
388 result = dns_rdata_tostruct(rdata, sp = &gpos, mctx);
389 break;
391 case dns_rdatatype_hinfo: {
392 dns_rdata_hinfo_t hinfo;
393 result = dns_rdata_tostruct(rdata, sp = &hinfo, mctx);
394 break;
396 case dns_rdatatype_isdn: {
397 dns_rdata_isdn_t isdn;
398 result = dns_rdata_tostruct(rdata, sp = &isdn, mctx);
399 break;
401 case dns_rdatatype_key: {
402 dns_rdata_key_t key;
403 result = dns_rdata_tostruct(rdata, sp = &key, mctx);
404 break;
406 case dns_rdatatype_kx: {
407 dns_rdata_in_kx_t in_kx;
408 result = dns_rdata_tostruct(rdata, sp = &in_kx, mctx);
409 break;
411 case dns_rdatatype_loc: {
412 dns_rdata_loc_t loc;
413 result = dns_rdata_tostruct(rdata, sp = &loc, mctx);
414 break;
416 case dns_rdatatype_mb: {
417 dns_rdata_mb_t mb;
418 result = dns_rdata_tostruct(rdata, sp = &mb, mctx);
419 break;
421 case dns_rdatatype_md: {
422 dns_rdata_md_t md;
423 result = dns_rdata_tostruct(rdata, sp = &md, mctx);
424 break;
426 case dns_rdatatype_mf: {
427 dns_rdata_mf_t mf;
428 result = dns_rdata_tostruct(rdata, sp = &mf, mctx);
429 break;
431 case dns_rdatatype_mg: {
432 dns_rdata_mg_t mg;
433 result = dns_rdata_tostruct(rdata, sp = &mg, mctx);
434 break;
436 case dns_rdatatype_minfo: {
437 dns_rdata_minfo_t minfo;
438 result = dns_rdata_tostruct(rdata, sp = &minfo, mctx);
439 break;
441 case dns_rdatatype_mr: {
442 dns_rdata_mr_t mr;
443 result = dns_rdata_tostruct(rdata, sp = &mr, mctx);
444 break;
446 case dns_rdatatype_mx: {
447 dns_rdata_mx_t mx;
448 result = dns_rdata_tostruct(rdata, sp = &mx, mctx);
449 break;
451 case dns_rdatatype_naptr: {
452 dns_rdata_in_naptr_t in_naptr;
453 result = dns_rdata_tostruct(rdata, sp = &in_naptr, mctx);
454 break;
456 case dns_rdatatype_ns: {
457 dns_rdata_ns_t ns;
458 result = dns_rdata_tostruct(rdata, sp = &ns, mctx);
459 break;
461 case dns_rdatatype_nsap: {
462 dns_rdata_in_nsap_t in_nsap;
463 result = dns_rdata_tostruct(rdata, sp = &in_nsap, mctx);
464 break;
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);
469 break;
471 case dns_rdatatype_null: {
472 dns_rdata_null_t null;
473 result = dns_rdata_tostruct(rdata, sp = &null, mctx);
474 break;
476 case dns_rdatatype_nxt: {
477 dns_rdata_nxt_t nxt;
478 result = dns_rdata_tostruct(rdata, sp = &nxt, mctx);
479 break;
481 case dns_rdatatype_opt: {
482 dns_rdata_opt_t opt;
483 result = dns_rdata_tostruct(rdata, sp = &opt, mctx);
484 break;
486 case dns_rdatatype_ptr: {
487 dns_rdata_ptr_t ptr;
488 result = dns_rdata_tostruct(rdata, sp = &ptr, mctx);
489 break;
491 case dns_rdatatype_px: {
492 dns_rdata_in_px_t in_px;
493 result = dns_rdata_tostruct(rdata, sp = &in_px, mctx);
494 break;
496 case dns_rdatatype_rp: {
497 dns_rdata_rp_t rp;
498 result = dns_rdata_tostruct(rdata, sp = &rp, mctx);
499 break;
501 case dns_rdatatype_rt: {
502 dns_rdata_rt_t rt;
503 result = dns_rdata_tostruct(rdata, sp = &rt, mctx);
504 break;
506 case dns_rdatatype_sig: {
507 dns_rdata_sig_t sig;
508 result = dns_rdata_tostruct(rdata, sp = &sig, mctx);
509 break;
511 case dns_rdatatype_soa: {
512 dns_rdata_soa_t soa;
513 result = dns_rdata_tostruct(rdata, sp = &soa, mctx);
514 break;
516 case dns_rdatatype_srv: {
517 dns_rdata_in_srv_t in_srv;
518 result = dns_rdata_tostruct(rdata, sp = &in_srv, mctx);
519 break;
521 case dns_rdatatype_tkey: {
522 dns_rdata_tkey_t tkey;
523 result = dns_rdata_tostruct(rdata, sp = &tkey, mctx);
524 break;
526 case dns_rdatatype_tsig: {
527 dns_rdata_any_tsig_t tsig;
528 result = dns_rdata_tostruct(rdata, sp = &tsig, mctx);
529 break;
531 case dns_rdatatype_txt: {
532 dns_rdata_txt_t txt;
533 result = dns_rdata_tostruct(rdata, sp = &txt, mctx);
534 break;
536 case dns_rdatatype_spf: {
537 dns_rdata_spf_t spf;
538 result = dns_rdata_tostruct(rdata, sp = &spf, mctx);
539 break;
541 case dns_rdatatype_unspec: {
542 dns_rdata_unspec_t unspec;
543 result = dns_rdata_tostruct(rdata, sp = &unspec, mctx);
544 break;
546 case dns_rdatatype_wks: {
547 dns_rdata_in_wks_t in_wks;
548 result = dns_rdata_tostruct(rdata, sp = &in_wks, mctx);
549 break;
551 case dns_rdatatype_x25: {
552 dns_rdata_x25_t x25;
553 result = dns_rdata_tostruct(rdata, sp = &x25, mctx);
554 break;
556 case dns_rdatatype_nsec: {
557 dns_rdata_nsec_t nsec;
558 result = dns_rdata_tostruct(rdata, sp = &nsec, mctx);
559 break;
561 case dns_rdatatype_rrsig: {
562 dns_rdata_rrsig_t rrsig;
563 result = dns_rdata_tostruct(rdata, sp = &rrsig, mctx);
564 break;
566 case dns_rdatatype_dnskey: {
567 dns_rdata_dnskey_t dnskey;
568 result = dns_rdata_tostruct(rdata, sp = &dnskey, mctx);
569 break;
571 default:
572 result = ISC_R_NOTIMPLEMENTED;
573 break;
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));
579 else {
580 need_free = ISC_TRUE;
582 rdc = rdata->rdclass;
583 rdt = rdata->type;
584 result = dns_rdata_fromstruct(rdata2, rdc, rdt, sp, b);
585 if (result != ISC_R_SUCCESS)
586 fprintf(stdout,
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)
593 isc_uint32_t i;
594 isc_uint32_t l;
596 fprintf(stdout, "viastruct: memcmp failed\n");
598 fprintf(stdout, "%d %d\n",
599 rdata->length, rdata2->length);
600 l = rdata->length;
601 if (rdata2->length < l)
602 l = rdata2->length;
603 for (i = 0; i < l; i++)
604 fprintf(stdout, "%02x %02x\n",
605 rdata->data[i], rdata2->data[i]);
608 #if 0
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);
613 break;
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,
620 &hs_a, b);
621 break;
623 case dns_rdataclass_in: {
624 dns_rdata_in_a_t in_a;
625 result = dns_rdata_fromstruct(rdata2, rdc, rdt,
626 &in_a, b);
627 break;
629 default:
630 result = ISC_R_NOTIMPLEMENTED;
631 break;
633 break;
635 case dns_rdatatype_aaaa: {
636 dns_rdata_in_aaaa_t in_aaaa;
637 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &in_aaaa, b);
638 break;
640 case dns_rdatatype_afsdb: {
641 dns_rdata_afsdb_t afsdb;
642 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &afsdb, b);
643 break;
645 case dns_rdatatype_any: {
646 result = ISC_R_NOTIMPLEMENTED;
647 break;
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);
654 break;
656 default:
657 result = ISC_R_NOTIMPLEMENTED;
658 break;
660 break;
662 case dns_rdatatype_cert: {
663 dns_rdata_cert_t cert;
664 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &cert, b);
665 break;
667 case dns_rdatatype_cname: {
668 dns_rdata_cname_t cname;
669 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &cname, b);
670 break;
672 case dns_rdatatype_dname: {
673 dns_rdata_dname_t dname;
674 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &dname, b);
675 break;
677 case dns_rdatatype_gpos: {
678 dns_rdata_gpos_t gpos;
679 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &gpos, b);
680 break;
682 case dns_rdatatype_hinfo: {
683 dns_rdata_hinfo_t hinfo;
684 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &hinfo, b);
685 break;
687 case dns_rdatatype_isdn: {
688 dns_rdata_isdn_t isdn;
689 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &isdn, b);
690 break;
692 case dns_rdatatype_key: {
693 dns_rdata_key_t key;
694 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &key, b);
695 break;
697 case dns_rdatatype_kx: {
698 dns_rdata_in_kx_t in_kx;
699 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &in_kx, b);
700 break;
702 case dns_rdatatype_loc: {
703 dns_rdata_loc_t loc;
704 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &loc, b);
705 break;
707 case dns_rdatatype_mb: {
708 dns_rdata_mb_t mb;
709 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &mb, b);
710 break;
712 case dns_rdatatype_md: {
713 dns_rdata_md_t md;
714 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &md, b);
715 break;
717 case dns_rdatatype_mf: {
718 dns_rdata_mf_t mf;
719 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &mf, b);
720 break;
722 case dns_rdatatype_mg: {
723 dns_rdata_mg_t mg;
724 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &mg, b);
725 break;
727 case dns_rdatatype_minfo: {
728 dns_rdata_minfo_t minfo;
729 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &minfo, b);
730 break;
732 case dns_rdatatype_mr: {
733 dns_rdata_mr_t mr;
734 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &mr, b);
735 break;
737 case dns_rdatatype_mx: {
738 dns_rdata_mx_t mx;
739 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &mx, b);
740 break;
742 case dns_rdatatype_naptr: {
743 dns_rdata_in_naptr_t in_naptr;
744 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &in_naptr, b);
745 break;
747 case dns_rdatatype_ns: {
748 dns_rdata_ns_t ns;
749 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &ns, b);
750 break;
752 case dns_rdatatype_nsap: {
753 dns_rdata_in_nsap_t in_nsap;
754 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &in_nsap, b);
755 break;
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,
761 break;
763 case dns_rdatatype_null: {
764 dns_rdata_null_t null;
765 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &null, b);
766 break;
768 case dns_rdatatype_nxt: {
769 dns_rdata_nxt_t nxt;
770 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &nxt, b);
771 break;
773 case dns_rdatatype_opt: {
774 dns_rdata_opt_t opt;
775 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &opt, b);
776 break;
778 case dns_rdatatype_ptr: {
779 dns_rdata_ptr_t ptr;
780 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &ptr, b);
781 break;
783 case dns_rdatatype_px: {
784 dns_rdata_in_px_t in_px;
785 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &in_px, b);
786 break;
788 case dns_rdatatype_rp: {
789 dns_rdata_rp_t rp;
790 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &rp, b);
791 break;
793 case dns_rdatatype_rt: {
794 dns_rdata_rt_t rt;
795 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &rt, b);
796 break;
798 case dns_rdatatype_sig: {
799 dns_rdata_sig_t sig;
800 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &sig, b);
801 break;
803 case dns_rdatatype_soa: {
804 dns_rdata_soa_t soa;
805 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &soa, b);
806 break;
808 case dns_rdatatype_srv: {
809 dns_rdata_in_srv_t in_srv;
810 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &in_srv, b);
811 break;
813 case dns_rdatatype_tkey: {
814 dns_rdata_tkey_t tkey;
815 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &tkey, b);
816 break;
818 case dns_rdatatype_tsig: {
819 dns_rdata_any_tsig_t tsig;
820 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &tsig, b);
821 break;
823 case dns_rdatatype_txt: {
824 dns_rdata_txt_t txt;
825 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &txt, b);
826 break;
828 case dns_rdatatype_spf: {
829 dns_rdata_spf_t spf;
830 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &spf, b);
831 break;
833 case dns_rdatatype_unspec: {
834 dns_rdata_unspec_t unspec;
835 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &unspec, b);
836 break;
838 case dns_rdatatype_wks: {
839 dns_rdata_in_wks_t in_wks;
840 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &in_wks, b);
841 break;
843 case dns_rdatatype_x25: {
844 dns_rdata_x25_t x25;
845 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &x25, b);
846 break;
848 case dns_rdatatype_nsec: {
849 dns_rdata_nsec_t nsec;
850 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &nsec, b);
851 break;
853 case dns_rdatatype_rrsig: {
854 dns_rdata_rrsig_t rrsig;
855 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &rrsig, b);
856 break;
858 case dns_rdatatype_dnskey: {
859 dns_rdata_dnskey_t dnskey;
860 result = dns_rdata_fromstruct(rdata2, rdc, rdt, &dnskey, b);
861 break;
863 default:
864 result = ISC_R_NOTIMPLEMENTED;
865 break;
867 #endif
868 if (need_free)
869 dns_rdata_freestruct(sp);
873 main(int argc, char *argv[]) {
874 isc_token_t token;
875 isc_result_t result;
876 int quiet = 0;
877 int c;
878 int stats = 0;
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];
884 char inbuf[16*1024];
885 char wirebuf[16*1024];
886 char viabuf[16*1024];
887 isc_buffer_t dbuf;
888 isc_buffer_t tbuf;
889 isc_buffer_t wbuf;
890 dns_rdata_t rdata = DNS_RDATA_INIT;
891 dns_rdata_t last = DNS_RDATA_INIT;
892 int need_eol = 0;
893 int wire = 0;
894 dns_compress_t cctx;
895 dns_decompress_t dctx;
896 int trunc = 0;
897 int add = 0;
898 int len;
899 int zero = 0;
900 int debug = 0;
901 isc_region_t region;
902 int first = 1;
903 int raw = 0;
904 int tostruct = 0;
906 while ((c = isc_commandline_parse(argc, argv, "dqswtarzS")) != -1) {
907 switch (c) {
908 case 'd':
909 debug = 1;
910 quiet = 0;
911 break;
912 case 'q':
913 quiet = 1;
914 debug = 0;
915 break;
916 case 's':
917 stats = 1;
918 break;
919 case 'w':
920 wire = 1;
921 break;
922 case 't':
923 trunc = 1;
924 break;
925 case 'a':
926 add = 1;
927 break;
928 case 'z':
929 zero = 1;
930 break;
931 case 'r':
932 raw++;
933 break;
934 case 'S':
935 tostruct++;
936 break;
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.
950 specials['('] = 1;
951 specials[')'] = 1;
952 specials['"'] = 1;
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);
963 if (need_eol) {
964 if (token.type == isc_tokentype_eol)
965 need_eol = 0;
966 continue;
968 if (token.type == isc_tokentype_eof)
969 break;
972 * Get type.
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) {
984 fprintf(stdout,
985 "dns_rdatatype_fromtext "
986 "returned %s(%d)\n",
987 dns_result_totext(result), result);
988 fflush(stdout);
989 need_eol = 1;
990 continue;
992 fprintf(stdout, "type = %.*s(%d)\n",
993 (int)token.value.as_textregion.length,
994 token.value.as_textregion.base, type);
995 } else
996 continue;
998 result = isc_lex_gettoken(lex, options | ISC_LEXOPT_NUMBER,
999 &token);
1000 if (result != ISC_R_SUCCESS)
1001 break;
1002 if (token.type == isc_tokentype_eol)
1003 continue;
1004 if (token.type == isc_tokentype_eof)
1005 break;
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);
1019 fflush(stdout);
1020 need_eol = 1;
1021 continue;
1023 fprintf(stdout, "class = %.*s(%d)\n",
1024 (int)token.value.as_textregion.length,
1025 token.value.as_textregion.base, class);
1026 } else
1027 continue;
1029 fflush(stdout);
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,
1034 NULL);
1035 if (result != ISC_R_SUCCESS) {
1036 fprintf(stdout,
1037 "dns_rdata_fromtext returned %s(%d)\n",
1038 dns_result_totext(result), result);
1039 fflush(stdout);
1040 continue;
1042 if (raw) {
1043 unsigned int i;
1044 for (i = 0; i < rdata.length; /* */ ) {
1045 fprintf(stdout, "%02x", rdata.data[i]);
1046 if ((++i % 20) == 0)
1047 fputs("\n", stdout);
1048 else
1049 if (i == rdata.length)
1050 fputs("\n", stdout);
1051 else
1052 fputs(" ", stdout);
1057 * Convert to wire and back?
1059 if (wire) {
1060 result = dns_compress_init(&cctx, -1, mctx);
1061 if (result != ISC_R_SUCCESS) {
1062 fprintf(stdout,
1063 "dns_compress_init returned %s(%d)\n",
1064 dns_result_totext(result), result);
1065 continue;
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) {
1071 fprintf(stdout,
1072 "dns_rdata_towire returned %s(%d)\n",
1073 dns_result_totext(result), result);
1074 continue;
1076 len = wbuf.used - wbuf.current;
1077 if (raw > 2) {
1078 unsigned int i;
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);
1085 else
1086 if (i == wbuf.used)
1087 fputs("\n", stdout);
1088 else
1089 fputs(" ", stdout);
1092 if (zero)
1093 len = 0;
1094 if (trunc)
1095 len = (len * 3) / 4;
1096 if (add) {
1097 isc_buffer_add(&wbuf, len / 4 + 1);
1098 len += 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,
1106 &dctx, 0, &dbuf);
1107 dns_decompress_invalidate(&dctx);
1108 if (result != ISC_R_SUCCESS) {
1109 fprintf(stdout,
1110 "dns_rdata_fromwire returned %s(%d)\n",
1111 dns_result_totext(result), result);
1112 fflush(stdout);
1113 continue;
1116 if (raw > 1) {
1117 unsigned int i;
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);
1123 else
1124 if (i == rdata.length)
1125 fputs("\n", stdout);
1126 else
1127 fputs(" ", stdout);
1130 if (tostruct) {
1131 isc_mem_t *mctx2 = NULL;
1132 dns_rdata_t rdata2 = DNS_RDATA_INIT;
1133 isc_buffer_t vbuf;
1135 RUNTIME_CHECK(isc_mem_create(0, 0, &mctx2)
1136 == ISC_R_SUCCESS);
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);
1151 else
1152 fprintf(stdout, "\"%.*s\"\n",
1153 (int)tbuf.used, (char*)tbuf.base);
1154 fflush(stdout);
1155 if (lasttype == type) {
1156 fprintf(stdout, "dns_rdata_compare = %d\n",
1157 dns_rdata_compare(&rdata, &last));
1160 if (!first) {
1161 free(last.data);
1163 dns_rdata_init(&last);
1164 region.base = malloc(region.length = rdata.length);
1165 if (region.base) {
1166 memcpy(region.base, rdata.data, rdata.length);
1167 dns_rdata_fromregion(&last, class, type, &region);
1168 lasttype = type;
1169 first = 0;
1170 } else
1171 first = 1;
1174 if (result != ISC_R_EOF)
1175 printf("Result: %s\n", isc_result_totext(result));
1177 isc_lex_close(lex);
1178 isc_lex_destroy(&lex);
1179 if (!quiet && stats)
1180 isc_mem_stats(mctx, stdout);
1181 isc_mem_destroy(&mctx);
1183 return (0);