Remove NULL queries. Remove _mf queries (master file format conversion).
[adns] / client / adnstest.c
1 /*
2 * dtest.c
3 * - simple test program, not part of the library
4 */
5 /*
6 * This file is part of adns, which is Copyright (C) 1997, 1998 Ian Jackson
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23 #include <stdio.h>
24 #include <unistd.h>
25 #include <assert.h>
26 #include <stdlib.h>
27
28 #include "adns.h"
29
30 static void failure(const char *what, adns_status st) {
31 fprintf(stderr,"adns failure: %s: %s\n",what,adns_strerror(st));
32 exit(2);
33 }
34
35 static const char *defaultargv[]= { "ns.chiark.greenend.org.uk", 0 };
36
37 static const adns_rrtype defaulttypes[]= {
38 adns_r_a,
39 adns_r_ns_raw,
40 adns_r_cname,
41 adns_r_ptr_raw,
42 adns_r_none
43 };
44
45 int main(int argc, const char *const *argv) {
46 adns_state ads;
47 adns_query *qus, qu;
48 adns_answer *ans;
49 const char *rrtn, *fmtn;
50 char *show;
51 int len, i, qc, qi, tc, ti;
52 adns_status r, ri;
53 const adns_rrtype *types;
54
55 if (argv[0] && argv[1]) argv++;
56 else argv= defaultargv;
57
58 types= defaulttypes;
59
60 for (qc=0; qc[argv]; qc++);
61 for (tc=0; types[tc] != adns_r_none; tc++);
62 qus= malloc(sizeof(qus)*qc*tc);
63 if (!qus) { perror("malloc qus"); exit(3); }
64
65 r= adns_init(&ads,adns_if_debug|adns_if_noautosys,0);
66 if (r) failure("init",r);
67
68 for (qi=0; qi<qc; qi++) {
69 for (ti=0; ti<tc; ti++) {
70 fprintf(stdout,"submitting %s %d\n",argv[qi],types[ti]);
71 r= adns_submit(ads,argv[qi],types[ti],0,0,&qus[qi*tc+ti]);
72 if (r) failure("submit",r);
73 }
74 }
75
76 for (qi=0; qi<qc; qi++) {
77 for (ti=0; ti<tc; ti++) {
78 qu= qus[qi*tc+ti];
79 r= adns_wait(ads,&qu,&ans,0);
80 if (r) failure("wait",r);
81
82 ri= adns_rr_info(ans->type, &rrtn,&fmtn,&len, 0,0);
83 fprintf(stdout, "%s: %s; nrrs=%d; cname=%s; ",
84 argv[qi], adns_strerror(ans->status),
85 ans->nrrs, ans->cname ? ans->cname : "$");
86 fprintf(stdout, "type %s(%s) %s\n",
87 ri ? "?" : rrtn, ri ? "?" : fmtn ? fmtn : "-",
88 adns_strerror(ri));
89 if (ans->nrrs) {
90 assert(!ri);
91 for (i=0; i<ans->nrrs; i++) {
92 r= adns_rr_info(ans->type, 0,0,0, ans->rrs.bytes+i*len,&show);
93 if (r) failure("info",r);
94 printf(" %s\n",show);
95 free(show);
96 }
97 }
98 free(ans);
99 }
100 }
101
102 free(qus);
103 exit(0);
104 }