From bf686ffabcc2b92bc4c8de248cf21b47f149b4a2 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Fri, 2 Mar 2012 17:47:01 +0100 Subject: [PATCH] dns: discover my ip address at runtime --- sys/src/cmd/ndb/dblookup.c | 10 +++++++++- sys/src/cmd/ndb/dns.c | 8 ++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/sys/src/cmd/ndb/dblookup.c b/sys/src/cmd/ndb/dblookup.c index fa7b92627..a704983c4 100644 --- a/sys/src/cmd/ndb/dblookup.c +++ b/sys/src/cmd/ndb/dblookup.c @@ -761,7 +761,8 @@ dnforceage(void) unlock(&dblock); } -extern uchar ipaddr[IPaddrlen]; /* my ip address */ +extern char mntpt[Maxpath]; /* net mountpoint */ +static uchar ipaddr[IPaddrlen]; /* my ip address */ /* * get all my xxx @@ -774,6 +775,10 @@ lookupinfo(char *attr) char *a[2]; Ndbtuple *t; + if(ipcmp(ipaddr, IPnoaddr) == 0) + if(myipaddr(ipaddr, mntpt) < 0) + return nil; + snprint(buf, sizeof buf, "%I", ipaddr); a[0] = attr; @@ -843,6 +848,9 @@ myaddr(char *addr) char buf[64]; Biobuf *bp; + if(ipcmp(ipaddr, IPnoaddr) == 0) + return -1; + snprint(buf, sizeof buf, "%I", ipaddr); if (strcmp(addr, buf) == 0) { dnslog("rejecting my ip %s as local dns server", addr); diff --git a/sys/src/cmd/ndb/dns.c b/sys/src/cmd/ndb/dns.c index 1bab66875..1bd0ef7fa 100644 --- a/sys/src/cmd/ndb/dns.c +++ b/sys/src/cmd/ndb/dns.c @@ -65,7 +65,6 @@ struct { Cfg cfg; int debug; -uchar ipaddr[IPaddrlen]; /* my ip address */ int maxage = Defmaxage; int mfd[2]; int needrefresh; @@ -191,15 +190,12 @@ main(int argc, char *argv[]) /* start syslog before we fork */ fmtinstall('F', fcallfmt); dninit(); - /* this really shouldn't be fatal */ - if(myipaddr(ipaddr, mntpt) < 0) - sysfatal("can't read my ip address"); - dnslog("starting %s%sdns %s%s%son %I's %s", + dnslog("starting %s%sdns %s%s%son %s", (cfg.straddle? "straddling ": ""), (cfg.cachedb? "caching ": ""), (cfg.serve? "udp server ": ""), (cfg.justforw? "forwarding-only ": ""), - (cfg.resolver? "resolver ": ""), ipaddr, mntpt); + (cfg.resolver? "resolver ": ""), mntpt); opendatabase(); now = time(nil); /* open time files before we fork */