X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=adns.git;a=blobdiff_plain;f=client%2Fadnstest.c;h=d8003dcde676a467acd00c2e6c119556779903fa;hp=6763babd28ff7d53075e29ecf934dc0bce6652e3;hb=a6536d8becc65c37fbeab7bc0793c6dd55bea977;hpb=964344fc6da09bb76aff991cbda338fe9c919d21 diff --git a/client/adnstest.c b/client/adnstest.c index 6763bab..d8003dc 100644 --- a/client/adnstest.c +++ b/client/adnstest.c @@ -1,14 +1,147 @@ -/**/ +/* + * dtest.c + * - simple test program, not part of the library + */ +/* + * This file is part of adns, which is Copyright (C) 1997, 1998 Ian Jackson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ #include +#include +#include +#include #include "adns.h" -int main(void) { +static void failure(const char *what, adns_status st) { + fprintf(stderr,"adns failure: %s: %s\n",what,adns_strerror(st)); + exit(2); +} + +static const char *defaultargv[]= { "ns.chiark.greenend.org.uk", 0 }; + +static const adns_rrtype defaulttypes[]= { + adns_r_a, + adns_r_ns_raw, + adns_r_cname, + adns_r_ptr_raw, + adns_r_mx_raw, + adns_r_txt, + adns_r_rp_raw, + adns_r_addr, + adns_r_ns, + adns_r_mx, + adns_r_ptr, + adns_r_none +}; + +static void dumptype(adns_status ri, const char *rrtn, const char *fmtn) { + fprintf(stdout, "%s(%s)%s%s", + ri ? "?" : rrtn, ri ? "?" : fmtn ? fmtn : "-", + ri ? " " : "", ri ? adns_strerror(ri) : ""); +} + +int main(int argc, char *const *argv) { adns_state ads; - int r; + adns_query *qus, qu; + adns_answer *ans; + const char *rrtn, *fmtn, *const *domlist; + char *show, *cp; + int len, i, qc, qi, tc, ti, ch; + adns_status r, ri; + const adns_rrtype *types; + adns_rrtype *types_a; + + if (argv[0] && argv[1] && argv[1][0] == ':') { + for (cp= argv[1]+1, tc=1; (ch= *cp); cp++) + if (ch==',') tc++; + types_a= malloc(sizeof(*types_a)*tc); + if (!types_a) { perror("malloc types"); exit(3); } + for (cp= argv[1]+1, ti=0; ti,...] [ ...]\n",stderr); + exit(4); + } + cp++; + } + } + types= types_a; + argv++; + } else { + types= defaulttypes; + } + + if (argv[0] && argv[1]) domlist= (const char *const*)argv+1; + else domlist= defaultargv; + + for (qc=0; qc[domlist]; qc++); + for (tc=0; types[tc] != adns_r_none; tc++); + qus= malloc(sizeof(qus)*qc*tc); + if (!qus) { perror("malloc qus"); exit(3); } + + r= adns_init(&ads,adns_if_debug|adns_if_noautosys,0); + if (r) failure("init",r); + + for (qi=0; qitype, &rrtn,&fmtn,&len, 0,0); + fprintf(stdout, "%s type ", domlist[qi]); + dumptype(ri,rrtn,fmtn); + fprintf(stdout, ": %s; nrrs=%d; cname=%s\n", + adns_strerror(ans->status), + ans->nrrs, ans->cname ? ans->cname : "$"); + if (ans->nrrs) { + assert(!ri); + for (i=0; inrrs; i++) { + r= adns_rr_info(ans->type, 0,0,0, ans->rrs.bytes+i*len,&show); + if (r) failure("info",r); + printf(" %s\n",show); + free(show); + } + } + free(ans); + } + } - r= adns_init(&ads,adns_if_debug); - if (r) { perror("init"); exit(2); } + free(qus); exit(0); }