diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2021-11-01 16:31:39 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2021-11-01 16:31:39 +0000 |
commit | 498d86b9218287b2b5c16aa54a283249fbd4e5a3 (patch) | |
tree | 62aae2bd8c7c45a7577c59142dee7468d877216a | |
parent | c67593125c93d80c281ee7a52ed81595ce2b7b92 (diff) |
ndb/dnsquery: make ! bang work with reverse lookups, document in ndb(8)
-rw-r--r-- | sys/man/8/ndb | 10 | ||||
-rw-r--r-- | sys/src/cmd/ndb/dnsquery.c | 40 |
2 files changed, 32 insertions, 18 deletions
diff --git a/sys/man/8/ndb b/sys/man/8/ndb index 28016f458..9ec933918 100644 --- a/sys/man/8/ndb +++ b/sys/man/8/ndb @@ -683,6 +683,9 @@ to see how it resolves requests. .I Ndb/dnsquery prompts for commands of the form .IP +[ +.B ! +] .I "domain-name request-type" .LP where @@ -700,6 +703,11 @@ In the case of the inverse query type, will reverse the ip address and tack on the .B .in-addr.arpa if necessary. +If the command starts with an exclamation mark +.B ! +then the response is returned in +.IR ndb (6) +format. The .B -x option switches @@ -707,7 +715,7 @@ option switches to query the dns server on .B /net.alt instead of -.B /net +.BR /net . .PP .I Ndb/dnsdebug is like diff --git a/sys/src/cmd/ndb/dnsquery.c b/sys/src/cmd/ndb/dnsquery.c index 952b69049..6f01878f8 100644 --- a/sys/src/cmd/ndb/dnsquery.c +++ b/sys/src/cmd/ndb/dnsquery.c @@ -53,41 +53,47 @@ static void query(int fd) { int n; - char *lp; + char *lp, *bang; char buf[1024], line[1024]; Biobuf in; Binit(&in, 0, OREAD); for(fprint(2, "> "); lp = Brdline(&in, '\n'); fprint(2, "> ")){ - n = Blinelen(&in) -1; - while(isspace(lp[n])) - lp[n--] = 0; - n++; - while(isspace(*lp)){ - lp++; + n = Blinelen(&in); + while(n > 0 && isspace(lp[n-1])) n--; + lp[n] = 0; + while(isspace(*lp)) + lp++; + bang = ""; + while(*lp == '!'){ + bang = "!"; + lp++; } - if(!*lp) + while(isspace(*lp)) + lp++; + if(*lp == 0) continue; - strcpy(line, lp); /* default to an "ip" request if alpha, "ptr" if numeric */ - if(strchr(line, ' ') == nil) - if(strcmp(ipattr(line), "ip") == 0) { - strcat(line, " ptr"); - n += 4; + if(strchr(lp, ' ') == nil){ + if(strcmp(ipattr(lp), "ip") == 0) { + n = snprint(line, sizeof line, "%s ptr", lp); } else { - strcat(line, " ip"); - n += 3; + n = snprint(line, sizeof line, "%s ip", lp); } + } else { + n = snprint(line, sizeof line, "%s", lp); + } if(n > 4 && strcmp(" ptr", &line[n-4]) == 0){ line[n-4] = 0; mkptrname(line, buf, sizeof buf); - n = snprint(line, sizeof line, "%s ptr", buf); + snprint(line, sizeof line, "%s ptr", buf); } - querydns(fd, line, n); + n = snprint(buf, sizeof buf, "%s%s", bang, line); + querydns(fd, buf, n); } Bterm(&in); } |