i don't know if it's any help, but here's some code that
i have used in the past to do a reverse dns lookup. it was under inferno and
the code's in limbo, but i think that /net/dns probably works
the same in both inferno and plan 9, so it should be cross-applicable.
it expects a host address of the form "123.45.67.89!9999" (as found in the
remote file) and returns the dns name.
hostname(addr: string): string
{
(nil, toks) := sys->tokenize(addr, "!");
if(len toks != 2)
return addr;
addr = hd toks;
if(NoDNS)
return addr;
a := addr2arpa(addr);
if(a == nil)
return addr;
fd := sys->open("/net/dns", Sys->ORDWR);
if(fd == nil)
return addr;
if(sys->fprint(fd, "%s ptr", a) < 0){
err := sys->sprint("%r");
log(sys->sprint("dnslookup failed %q %q", addr, err));
return addr;
}
buf := array[1024] of byte;
sys->seek(fd, big 0, 0);
n := sys->read(fd, buf, len buf);
if(n <= 0)
return addr;
a = string buf[0:n];
for(i := 0; i < len a; i++)
if(a[i] == '\t')
break;
if(i == len a)
return addr;
i++;
# return address of the form:
# 68.1.1.200.in-addr.arpa ptr presto.vitanuova.com(0)
for(j := len a - 1; j > i; j--)
if(a[j] == '(')
return a[i:j];
return a[i:];
}
addr2arpa(a: string): string
{
addr := "in-addr.arpa";
for(toks := sys->tokenize(a, ".").t1; toks != nil; toks = tl toks)
addr = hd toks + "." + addr;
return addr;
}