ref: bf686ffabcc2b92bc4c8de248cf21b47f149b4a2
parent: d8a60343baca2cc85084e18a817dbf2f0e816dd7
author: cinap_lenrek <[email protected]>
date: Fri Mar 2 12:47:01 EST 2012
dns: discover my ip address at runtime
--- a/sys/src/cmd/ndb/dblookup.c
+++ b/sys/src/cmd/ndb/dblookup.c
@@ -761,7 +761,8 @@
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 @@
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;
@@ -842,6 +847,9 @@
char *name, *line, *sp;
char buf[64];
Biobuf *bp;
+
+ if(ipcmp(ipaddr, IPnoaddr) == 0)
+ return -1;
snprint(buf, sizeof buf, "%I", ipaddr);
if (strcmp(addr, buf) == 0) {
--- a/sys/src/cmd/ndb/dns.c
+++ b/sys/src/cmd/ndb/dns.c
@@ -65,7 +65,6 @@
Cfg cfg;
int debug;
-uchar ipaddr[IPaddrlen]; /* my ip address */
int maxage = Defmaxage;
int mfd[2];
int needrefresh;
@@ -191,15 +190,12 @@
/* 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 */