From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <43a472778ecc6f0f1f2a36fa18632cd5@vitanuova.com> To: 9fans@cse.psu.edu Subject: Re: [9fans] csipinfo Date: Wed, 18 Oct 2006 17:59:03 +0100 From: rog@vitanuova.com In-Reply-To: <7871fcf50610180943k338de32fqd95d2ad178cca96a@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Topicbox-Message-UUID: ccbf8262-ead1-11e9-9d60-3106f5b1d025 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; }