3 * - simple test program, not part of the library
6 * This file is part of adns, which is Copyright (C) 1997-1999 Ian Jackson
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)
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.
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.
29 # define OUTPUTSTREAM stdout
34 static void failure(const char *what
, adns_status st
) {
35 fprintf(stderr
,"adns failure: %s: %s\n",what
,adns_strerror(st
));
39 static const char *defaultargv
[]= { "ns.chiark.greenend.org.uk", 0 };
41 static const adns_rrtype defaulttypes
[]= {
64 static void dumptype(adns_status ri
, const char *rrtn
, const char *fmtn
) {
65 fprintf(stdout
, "%s(%s)%s%s",
66 ri ?
"?" : rrtn
, ri ?
"?" : fmtn ? fmtn
: "-",
67 ri ?
" " : "", ri ?
adns_strerror(ri
) : "");
70 int main(int argc
, char *const *argv
) {
74 const char *initstring
, *rrtn
, *fmtn
;
75 const char *const *domlist
;
77 int len
, i
, qc
, qi
, tc
, ti
, ch
;
79 const adns_rrtype
*types
;
82 if (argv
[0] && argv
[1] && argv
[1][0] == '/') {
83 initstring
= argv
[1]+1;
89 if (argv
[0] && argv
[1] && argv
[1][0] == ':') {
90 for (cp
= argv
[1]+1, tc
=1; (ch
= *cp
); cp
++)
92 types_a
= malloc(sizeof(*types_a
)*tc
);
93 if (!types_a
) { perror("malloc types"); exit(3); }
94 for (cp
= argv
[1]+1, ti
=0; ti
<tc
; ti
++) {
95 types_a
[ti
]= strtoul(cp
,&cp
,10);
98 fputs("usage: dtest [/<initstring>] [:<typenum>,...] [<domain> ...]\n",stderr
);
110 if (argv
[0] && argv
[1]) domlist
= (const char *const*)argv
+1;
111 else domlist
= defaultargv
;
113 for (qc
=0; qc
[domlist
]; qc
++);
114 for (tc
=0; types
[tc
] != adns_r_none
; tc
++);
115 qus
= malloc(sizeof(qus
)*qc
*tc
);
116 if (!qus
) { perror("malloc qus"); exit(3); }
119 r
= adns_init_strcfg(&ads
,adns_if_debug
|adns_if_noautosys
,stdout
,initstring
);
121 r
= adns_init(&ads
,adns_if_debug
|adns_if_noautosys
,0);
123 if (r
) failure("init",r
);
125 for (qi
=0; qi
<qc
; qi
++) {
126 for (ti
=0; ti
<tc
; ti
++) {
127 fprintf(stdout
,"%s type %d",domlist
[qi
],types
[ti
]);
128 r
= adns_submit(ads
,domlist
[qi
],types
[ti
],0,0,&qus
[qi
*tc
+ti
]);
129 if (r
== adns_s_unknownrrtype
) {
130 fprintf(stdout
," not implemented\n");
135 ri
= adns_rr_info(types
[ti
], &rrtn
,&fmtn
,0, 0,0);
137 dumptype(ri
,rrtn
,fmtn
);
138 fprintf(stdout
," submitted\n");
143 for (qi
=0; qi
<qc
; qi
++) {
144 for (ti
=0; ti
<tc
; ti
++) {
147 r
= adns_wait(ads
,&qu
,&ans
,0);
148 if (r
) failure("wait",r
);
150 ri
= adns_rr_info(ans
->type
, &rrtn
,&fmtn
,&len
, 0,0);
151 fprintf(stdout
, "%s type ", domlist
[qi
]);
152 dumptype(ri
,rrtn
,fmtn
);
153 fprintf(stdout
, ": %s; nrrs=%d; cname=%s\n",
154 adns_strerror(ans
->status
),
155 ans
->nrrs
, ans
->cname ? ans
->cname
: "$");
158 for (i
=0; i
<ans
->nrrs
; i
++) {
159 r
= adns_rr_info(ans
->type
, 0,0,0, ans
->rrs
.bytes
+i
*len
,&show
);
160 if (r
) failure("info",r
);
161 fprintf(stdout
," %s\n",show
);