X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=client%2Fadnsresfilter.c;h=f2657734cb833dbf2a314d136fe63e4347e61870;hb=4b2c4f8a37e33604c1aeddafe49b7c33089692a4;hp=136929d24fdfb2589bb6800fe98abdba0662fc04;hpb=41559f53541ae03b5647c41c42883dc4b78634d9;p=adns.git diff --git a/client/adnsresfilter.c b/client/adnsresfilter.c index 136929d..f265773 100644 --- a/client/adnsresfilter.c +++ b/client/adnsresfilter.c @@ -49,7 +49,7 @@ struct outqueuenode { struct treething *addr; }; -static int bracket, forever; +static int bracket, forever, address; static unsigned long timeout=100; static adns_rrtype rrt= adns_r_ptr; @@ -109,10 +109,13 @@ static void outputerr(void) { sysfail("write to stdout"); } static void usage(void) { if (printf("usage: adnsresfilter []\n" " adnsresfilter -h|--help\n" - "options: -b|--brackets\n" - " -w|--wait\n" - " -t|--timeout \n" - " -u|--unchecked\n") + "options: -t|--timeout \n" + " -w|--wait (always wait for queries to time out or fail)\n" + " -b|--brackets (require [...] around IP addresses)\n" + " -a|--address (always include [address] in output)\n" + " -u|--unchecked (do not forward map for checking)\n" + "Timeout is the maximum amount to delay any particular bit of output for.\n" + "Lookups will go on in the background. Default timeout = 100 (ms).\n") == EOF) outputerr(); } @@ -148,6 +151,8 @@ static void parseargs(const char *const *argv) { rrt= adns_r_ptr_raw; } else if (!strcmp(arg,"--wait")) { forever= 1; + } else if (!strcmp(arg,"--address")) { + address= 1; } else if (!strcmp(arg,"--help")) { usage(); quit(0); } else if (!strcmp(arg,"--timeout")) { @@ -169,6 +174,9 @@ static void parseargs(const char *const *argv) { case 'w': forever= 1; break; + case 'a': + address= 1; + break; case 'h': usage(); quit(0); @@ -232,10 +240,24 @@ static void writestdout(struct outqueuenode *entry) { } static void replacetextwithname(struct outqueuenode *entry) { - free(entry->buffer); - entry->buffer= 0; - entry->textp= entry->addr->ans->rrs.str[0]; - entry->textlen= strlen(entry->textp); + char *name, *newbuf; + int namelen, newlen; + + name= entry->addr->ans->rrs.str[0]; + namelen= strlen(name); + if (!address) { + free(entry->buffer); + entry->buffer= 0; + entry->textp= name; + entry->textlen= namelen; + } else { + newlen= entry->textlen + namelen + (bracket ? 0 : 2); + newbuf= xmalloc(newlen + 1); + sprintf(newbuf, bracket ? "%s%.*s" : "%s[%.*s]", name, entry->textlen, entry->textp); + free(entry->buffer); + entry->buffer= entry->textp= newbuf; + entry->textlen= newlen; + } } static void checkadnsqueries(void) {