From 00da3130b735faefecfd09cc4081bf35e8dddffd Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 2 Jul 2000 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2000-07-02 --- boot/bootip.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/boot/bootip.c b/boot/bootip.c index 74d9e382183ccd385ff01dd1d32298a3792501fe..e60750b41066a83901c2413b702aa5c7f80c3d1e 100644 --- a/boot/bootip.c +++ b/boot/bootip.c @@ -10,6 +10,7 @@ static char mpoint[32]; static int isvalidip(uchar*); static void netndb(char*, uchar*); +static void netenv(char*, uchar*); void configip(void) @@ -76,13 +77,18 @@ configip(void) /* if we didn't get a file and auth server, query user */ netndb("fs", fsip); - netndb("auth", auip); - if(!isvalidip(fsip)){ + if(!isvalidip(fsip)) + netenv("fs", fsip); + while(!isvalidip(fsip)){ buf[0] = 0; outin("filesystem IP address", buf, sizeof(buf)); parseip(fsip, buf); } - if(!isvalidip(auip)){ + + netndb("auth", auip); + if(!isvalidip(auip)) + netenv("auth", auip); + while(!isvalidip(auip)){ buf[0] = 0; outin("authentication server IP address", buf, sizeof(buf)); parseip(auip, buf); @@ -150,6 +156,25 @@ isvalidip(uchar *ip) return 1; } +static void +netenv(char *attr, uchar *ip) +{ + int fd, n; + char buf[128]; + + ipmove(ip, IPnoaddr); + snprint(buf, sizeof(buf), "#e/%s", attr); + fd = open(buf, OREAD); + if(fd < 0) + return; + + n = read(fd, buf, sizeof(buf)-1); + if(n <= 0) + return; + buf[n] = 0; + parseip(ip, buf); +} + static void netndb(char *attr, uchar *ip) { @@ -176,8 +201,9 @@ netndb(char *attr, uchar *ip) if(*(p + n) == '=' && (p == buf || c == '\n' || c == ' ' || c == '\t')){ p += n+1; parseip(ip, p); - break; + return; } p++; } + return; }