3 * - simple test program, not part of the library
6 * This file is part of adns, which is Copyright (C) 1997, 1998 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.
30 static void failure(const char *what
, adns_status st
) {
31 fprintf(stderr
,"adns failure: %s: %s\n",what
,adns_strerror(st
));
35 static const char *defaultargv
[]= { "ns.chiark.greenend.org.uk", 0 };
37 int main(int argc
, const char *const *argv
) {
41 const char *rrtn
, *fmtn
;
46 if (argv
[0] && argv
[1]) argv
++;
47 else argv
= defaultargv
;
49 for (qc
=0; qc
[argv
]; qc
++);
50 qus
= malloc(sizeof(qus
)*qc
);
51 if (!qus
) { perror("malloc qus"); exit(3); }
53 r
= adns_init(&ads
,adns_if_debug
|adns_if_noautosys
,0);
54 if (r
) failure("init",r
);
56 for (qi
=0; qi
<qc
; qi
++) {
57 r
= adns_submit(ads
,argv
[qi
],adns_r_a
,0,0,&qus
[qi
]);
58 if (r
) failure("submit",r
);
61 for (qi
=0; qi
<qc
; qi
++) {
63 r
= adns_wait(ads
,&qu
,&ans
,0);
64 if (r
) failure("wait",r
);
66 ri
= adns_rr_info(ans
->type
, &rrtn
,&fmtn
,&len
, 0,0);
67 fprintf(stdout
, "%s: %s; nrrs=%d; cname=%s; ",
68 argv
[qi
], adns_strerror(ans
->status
),
69 ans
->nrrs
, ans
->cname ? ans
->cname
: "$");
70 fprintf(stdout
, "type %s(%s) %s\n",
71 ri ?
"?" : rrtn
, ri ?
"?" : fmtn ? fmtn
: "-",
75 for (i
=0; i
<ans
->nrrs
; i
++) {
76 r
= adns_rr_info(ans
->type
, 0,0,0, ans
->rrs
.bytes
+i
*len
,&show
);
77 if (r
) failure("info",r
);