ndb/dnsquery: make ! bang work with reverse lookups, document in ndb(8)

This commit is contained in:
cinap_lenrek 2021-11-01 16:31:39 +00:00
parent c67593125c
commit 498d86b921
2 changed files with 32 additions and 18 deletions

View file

@ -683,6 +683,9 @@ to see how it resolves requests.
.I Ndb/dnsquery .I Ndb/dnsquery
prompts for commands of the form prompts for commands of the form
.IP .IP
[
.B !
]
.I "domain-name request-type" .I "domain-name request-type"
.LP .LP
where where
@ -700,6 +703,11 @@ In the case of the inverse query type,
will reverse the ip address and tack on the will reverse the ip address and tack on the
.B .in-addr.arpa .B .in-addr.arpa
if necessary. if necessary.
If the command starts with an exclamation mark
.B !
then the response is returned in
.IR ndb (6)
format.
The The
.B -x .B -x
option switches option switches
@ -707,7 +715,7 @@ option switches
to query the dns server on to query the dns server on
.B /net.alt .B /net.alt
instead of instead of
.B /net .BR /net .
.PP .PP
.I Ndb/dnsdebug .I Ndb/dnsdebug
is like is like

View file

@ -53,41 +53,47 @@ static void
query(int fd) query(int fd)
{ {
int n; int n;
char *lp; char *lp, *bang;
char buf[1024], line[1024]; char buf[1024], line[1024];
Biobuf in; Biobuf in;
Binit(&in, 0, OREAD); Binit(&in, 0, OREAD);
for(fprint(2, "> "); lp = Brdline(&in, '\n'); fprint(2, "> ")){ for(fprint(2, "> "); lp = Brdline(&in, '\n'); fprint(2, "> ")){
n = Blinelen(&in) -1; n = Blinelen(&in);
while(isspace(lp[n])) while(n > 0 && isspace(lp[n-1]))
lp[n--] = 0;
n++;
while(isspace(*lp)){
lp++;
n--; n--;
lp[n] = 0;
while(isspace(*lp))
lp++;
bang = "";
while(*lp == '!'){
bang = "!";
lp++;
} }
if(!*lp) while(isspace(*lp))
lp++;
if(*lp == 0)
continue; continue;
strcpy(line, lp);
/* default to an "ip" request if alpha, "ptr" if numeric */ /* default to an "ip" request if alpha, "ptr" if numeric */
if(strchr(line, ' ') == nil) if(strchr(lp, ' ') == nil){
if(strcmp(ipattr(line), "ip") == 0) { if(strcmp(ipattr(lp), "ip") == 0) {
strcat(line, " ptr"); n = snprint(line, sizeof line, "%s ptr", lp);
n += 4;
} else { } else {
strcat(line, " ip"); n = snprint(line, sizeof line, "%s ip", lp);
n += 3;
} }
} else {
n = snprint(line, sizeof line, "%s", lp);
}
if(n > 4 && strcmp(" ptr", &line[n-4]) == 0){ if(n > 4 && strcmp(" ptr", &line[n-4]) == 0){
line[n-4] = 0; line[n-4] = 0;
mkptrname(line, buf, sizeof buf); 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); Bterm(&in);
} }