X-Git-Url: https://git.distorted.org.uk/~mdw/adns/blobdiff_plain/1aa0213d64572362fbf4be15fba8309c6e10384c..620c146da30a20c2d9a6c572fdd0540558039d0e:/client/adnstest.c diff --git a/client/adnstest.c b/client/adnstest.c index 4f2b982..52344d1 100644 --- a/client/adnstest.c +++ b/client/adnstest.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifndef OUTPUTSTREAM # define OUTPUTSTREAM stdout @@ -32,11 +33,16 @@ #include "adns.h" -static void failure(const char *what, adns_status st) { +static void failure_status(const char *what, adns_status st) { fprintf(stderr,"adns failure: %s: %s\n",what,adns_strerror(st)); exit(2); } +static void failure_errno(const char *what, int errnoval) { + fprintf(stderr,"adns failure: %s: errno=%d\n",what,errnoval); + exit(2); +} + static const char *defaultargv[]= { "ns.chiark.greenend.org.uk", 0 }; static const adns_rrtype defaulttypes[]= { @@ -67,13 +73,22 @@ static void dumptype(adns_status ri, const char *rrtn, const char *fmtn) { ri ? " " : "", ri ? adns_strerror(ri) : ""); } -static void fdom_split(const char *fdom, const char **dom_r, int *qf_r) { +static void fdom_split(const char *fdom, const char **dom_r, int *qf_r, + char *ownflags, int ownflags_l) { int qf; char *ep; qf= strtoul(fdom,&ep,0); + if (*ep == ',' && strchr(ep,'/')) { + ep++; + while (*ep != '/') { + if (--ownflags_l <= 0) { fputs("too many flags\n",stderr); exit(3); } + *ownflags++= *ep++; + } + } if (*ep != '/') { *dom_r= fdom; *qf_r= 0; } else { *dom_r= ep+1; *qf_r= qf; } + *ownflags= 0; } int main(int argc, char *const *argv) { @@ -88,6 +103,7 @@ int main(int argc, char *const *argv) { const adns_rrtype *types; struct timeval now; adns_rrtype *types_a; + char ownflags[10]; if (argv[0] && argv[1] && argv[1][0] == '/') { initstring= argv[1]+1; @@ -99,7 +115,7 @@ int main(int argc, char *const *argv) { 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); + types_a= malloc(sizeof(*types_a)*(tc+1)); if (!types_a) { perror("malloc types"); exit(3); } for (cp= argv[1]+1, ti=0; titype, &rrtn,&fmtn,&len, 0,0); fprintf(stdout, "%s flags %d type ",domain,qflags); dumptype(ri,rrtn,fmtn); - fprintf(stdout, ": %s; nrrs=%d; cname=%s; owner=%s; ttl=%ld\n", - adns_strerror(ans->status), + fprintf(stdout, "%s%s: %s; nrrs=%d; cname=%s; owner=%s; ttl=%ld\n", + ownflags[0] ? " ownflags=" : "", ownflags, + strchr(ownflags,'a') ? adns_errabbrev(ans->status) + : adns_strerror(ans->status), ans->nrrs, ans->cname ? ans->cname : "$", ans->owner ? ans->owner : "$", @@ -175,8 +194,8 @@ int main(int argc, char *const *argv) { 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); + r= adns_rr_info(ans->type, 0,0,0, ans->rrs.bytes + i*len, &show); + if (r) failure_status("info",r); fprintf(stdout," %s\n",show); free(show); }