X-Git-Url: https://git.distorted.org.uk/~mdw/adns/blobdiff_plain/350d37d91f274691a71c2d41854773a2f832cf07..86e7b8d96483d2f55561aa76ac96e7663840b796:/client/adnstest.c diff --git a/client/adnstest.c b/client/adnstest.c index 2ad2cc0..46a0258 100644 --- a/client/adnstest.c +++ b/client/adnstest.c @@ -1,20 +1,87 @@ -/**/ +/* + * 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 }; + +int main(int argc, const char *const *argv) { adns_state ads; - adns_query qu; - int r; + adns_query *qus, qu; + adns_answer *ans; + const char *rrtn, *fmtn; + char *show; + int len, i, qc, qi; + adns_status r, ri; + + if (argv[0] && argv[1]) argv++; + else argv= defaultargv; + + for (qc=0; qc[argv]; qc++); + qus= malloc(sizeof(qus)*qc); + 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: %s; nrrs=%d; cname=%s; ", + argv[qi], adns_strerror(ans->status), + ans->nrrs, ans->cname ? ans->cname : "$"); + fprintf(stdout, "type %s(%s) %s\n", + ri ? "?" : rrtn, ri ? "?" : fmtn ? fmtn : "-", + adns_strerror(ri)); + 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_submit(ads,"anarres.greenend.org.uk",adns_r_a,0,0,&qu); - if (r) { perror("submit"); exit(2); } - + free(qus); exit(0); }