dns: discover my ip address at runtime

front
cinap_lenrek 2012-03-02 17:47:01 +01:00
parent d8a60343ba
commit bf686ffabc
2 changed files with 11 additions and 7 deletions

View File

@ -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);

View File

@ -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 */