From: Joel âcheskyâ Salomon <chesky@plan9.jp>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] csipinfo
Date: Wed, 18 Oct 2006 16:17:19 -0400 [thread overview]
Message-ID: <f0350d8cfafc8751c821b0434be0066e@plan9.jp> (raw)
In-Reply-To: <365a3b8e0ce821506adb926ac1001503@plan9.jp>
I think I have a working gethostbyaddr:
char*
gethostbyaddr(char *net, char *addr)
{
// Thanks to erik and rog for their help with this code
char buf[1024], errbuf[ERRMAX], *dq[4], *host;
int fd, l;
if(net == nil)
net = "/net";
snprint(buf, sizeof buf, "%s/dns", net);
if((fd = open(buf, ORDWR)) < 0){
l = snprint(errbuf, ERRMAX, "gethostbyaddr: can't open %s: %r", buf);
errstr(errbuf, l);
return nil;
}
if(getfields(addr, dq, 4, 1, ".") != 4){
close(fd);
werrstr("gethostbyaddr: malformed address");
return nil;
}
l = snprint(buf, sizeof buf, "%s.%s.%s.%s.in-addr.arpa ptr",
dq[3], dq[2], dq[1], dq[0]);
if(write(fd, buf, l) != l){
l = snprint(errbuf, ERRMAX,
"gethostbyaddr: write error resolving %s.%s.%s.%s: %s/dns: %r",
dq[0], dq[1], dq[2], dq[3], net);
close(fd);
errstr(errbuf, l);
return nil;
}
if(read(fd, buf, sizeof buf) <= 0){
l = snprint(errbuf, ERRMAX,
"gethostbyaddr: read error resolving %s.%s.%s.%s: %s/dns: %r",
dq[0], dq[1], dq[2], dq[3], net);
close(fd);
errstr(errbuf, l);
return nil;
}
close(fd);
host = strstr(buf, " ptr ");
if(host == nil){
werrstr("gethostbyaddr: dns lookup failed");
return nil;
}
return strdup(host);
}
--Joel
next prev parent reply other threads:[~2006-10-18 20:17 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
[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 [this message]
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
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
2006-10-18 20:38 ` andrey mirtchovski
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=f0350d8cfafc8751c821b0434be0066e@plan9.jp \
--to=chesky@plan9.jp \
--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).