From: rog@vitanuova.com
To: 9fans@cse.psu.edu
Subject: Re: [9fans] csipinfo
Date: Wed, 18 Oct 2006 17:59:03 +0100 [thread overview]
Message-ID: <43a472778ecc6f0f1f2a36fa18632cd5@vitanuova.com> (raw)
In-Reply-To: <7871fcf50610180943k338de32fqd95d2ad178cca96a@mail.gmail.com>
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;
}
next prev parent reply other threads:[~2006-10-18 16:59 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-18 3:10 Joel “chesky” Salomon
2006-10-18 3:36 ` geoff
2006-10-18 5:20 ` Joel “chesky” Salomon
2006-10-18 5:37 ` geoff
2006-10-18 5:53 ` Joel “chesky” Salomon
2006-10-18 12:38 ` Joel “chesky” Salomon
2006-10-18 15:32 ` Russ Cox
2006-10-18 16:43 ` Joel Salomon
2006-10-18 16:59 ` rog [this message]
2006-10-18 20:38 ` andrey mirtchovski
[not found] <61d9157e8f6994d999d7f257cd2b05b4@coraid.com>
2006-10-18 18:44 ` Joel “chesky” Salomon
2006-10-18 19:14 ` rog
2006-10-18 19:26 ` erik quanstrom
2006-10-18 19:38 ` Joel “chesky” Salomon
2006-10-18 19:57 ` C H Forsyth
2006-10-18 23:51 ` Charles Forsyth
2006-10-19 8:29 ` Charles Forsyth
2006-10-18 20:17 ` Joel “chesky” Salomon
2006-10-18 21:29 ` geoff
2006-10-18 19:56 ` Charles Forsyth
2006-10-18 19:59 ` erik quanstrom
2006-10-18 20:15 ` rog
2006-10-18 19:30 ` erik quanstrom
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43a472778ecc6f0f1f2a36fa18632cd5@vitanuova.com \
--to=rog@vitanuova.com \
--cc=9fans@cse.psu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).