summaryrefslogtreecommitdiff
path: root/sys/src/cmd/ndb
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2018-05-23 19:44:12 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2018-05-23 19:44:12 +0200
commitad7390dda820db424821b19c572a44b4cc0838e8 (patch)
treeeea5128c5a8a88b7ac004544c8d68034bce19a7c /sys/src/cmd/ndb
parent03ced8cca1c2c2911ba64e937af8436658d126d5 (diff)
ndb/dnsdebug: handle .ip6.arpa names
Diffstat (limited to 'sys/src/cmd/ndb')
-rw-r--r--sys/src/cmd/ndb/dnsdebug.c66
1 files changed, 37 insertions, 29 deletions
diff --git a/sys/src/cmd/ndb/dnsdebug.c b/sys/src/cmd/ndb/dnsdebug.c
index b2f3cebf2..01377598a 100644
--- a/sys/src/cmd/ndb/dnsdebug.c
+++ b/sys/src/cmd/ndb/dnsdebug.c
@@ -121,6 +121,32 @@ longtime(long t)
return x;
}
+/*
+ * convert address into a reverse lookup address
+ */
+static void
+mkptrname(char *ip, char *rip, int rlen)
+{
+ uchar a[IPaddrlen];
+ char *p, *e;
+ int i;
+
+ if(cistrstr(ip, "in-addr.arpa") || cistrstr(ip, "ip6.arpa") || parseip(a, ip) == -1)
+ snprint(rip, rlen, "%s", ip);
+ else if(isv4(a))
+ snprint(rip, rlen, "%ud.%ud.%ud.%ud.in-addr.arpa",
+ a[15], a[14], a[13], a[12]);
+ else{
+ p = rip;
+ e = rip + rlen;
+ for(i = 15; i >= 0; i--){
+ p = seprint(p, e, "%ux.", a[i]&0xf);
+ p = seprint(p, e, "%ux.", a[i]>>4);
+ }
+ seprint(p, e, "ip6.arpa");
+ }
+}
+
int
prettyrrfmt(Fmt *f)
{
@@ -372,7 +398,6 @@ void
doquery(char *name, char *tstr)
{
int len, type, rooted;
- char *p, *np;
char buf[1024];
RR *rr, *rp;
Request req;
@@ -387,6 +412,13 @@ doquery(char *name, char *tstr)
else
tstr = "ip";
+ /* look it up */
+ type = rrtype(tstr);
+ if(type < 0){
+ print("!unknown type %s\n", tstr);
+ return;
+ }
+
/* if name end in '.', remove it */
len = strlen(name);
if(len > 0 && name[len-1] == '.'){
@@ -396,34 +428,10 @@ doquery(char *name, char *tstr)
rooted = 0;
/* inverse queries may need to be permuted */
- strncpy(buf, name, sizeof buf);
- if(strcmp("ptr", tstr) == 0 && cistrstr(name, ".arpa") == nil){
- /* TODO: reversing v6 addrs is harder */
- for(p = name; *p; p++)
- ;
- *p = '.';
- np = buf;
- len = 0;
- while(p >= name){
- len++;
- p--;
- if(*p == '.'){
- memmove(np, p+1, len);
- np += len;
- len = 0;
- }
- }
- memmove(np, p+1, len);
- np += len;
- strcpy(np, "in-addr.arpa"); /* TODO: ip6.arpa for v6 */
- }
-
- /* look it up */
- type = rrtype(tstr);
- if(type < 0){
- print("!unknown type %s\n", tstr);
- return;
- }
+ if(type == Tptr)
+ mkptrname(name, buf, sizeof buf);
+ else
+ strncpy(buf, name, sizeof buf);
memset(&req, 0, sizeof req);
getactivity(&req, 0);