summaryrefslogtreecommitdiff
path: root/sys/src/cmd/ip/ipconfig/dhcp.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2018-09-25 15:02:29 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2018-09-25 15:02:29 +0200
commit12b3c82014efd24fa57037c001c7d3ce78204e5a (patch)
treed99820e4cc013dce4b69497fe94db256cfd3b229 /sys/src/cmd/ip/ipconfig/dhcp.c
parent2f076f946fe7a5409cda7d83af5585442b294ec8 (diff)
ip/ipconfig: implement rfc3397 dhcp dns search option (dnsdomain)
Diffstat (limited to 'sys/src/cmd/ip/ipconfig/dhcp.c')
-rw-r--r--sys/src/cmd/ip/ipconfig/dhcp.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/sys/src/cmd/ip/ipconfig/dhcp.c b/sys/src/cmd/ip/ipconfig/dhcp.c
index a312d2c07..b9453334e 100644
--- a/sys/src/cmd/ip/ipconfig/dhcp.c
+++ b/sys/src/cmd/ip/ipconfig/dhcp.c
@@ -17,6 +17,7 @@ enum
Tbyte,
Tulong,
Tvec,
+ Tnames,
};
typedef struct Option Option;
@@ -107,10 +108,11 @@ static Option option[256] =
[ODclientid] { "clientid", Tvec },
[ODtftpserver] { "tftp", Taddr },
[ODbootfile] { "bootfile", Tstr },
+[ODdnsdomain] { "dnsdomain", Tnames },
};
static uchar defrequested[] = {
- OBmask, OBrouter, OBdnserver, OBhostname, OBdomainname, OBntpserver,
+ OBmask, OBrouter, OBdnserver, OBhostname, OBdomainname, ODdnsdomain, OBntpserver,
};
static uchar requested[256];
@@ -139,6 +141,7 @@ static uchar* optget(uchar*, int, int*);
static ulong optgetulong(uchar*, int);
static int optgetvec(uchar*, int, uchar*, int);
static char* optgetx(uchar*, uchar);
+static int optgetnames(uchar*, int, char*, int);
static void getoptions(uchar*);
static int parseoptions(uchar *p, int n);
@@ -513,10 +516,15 @@ dhcprecv(void)
DEBUG("ntp=%I ", conf.ntp + i*IPaddrlen);
/* get names */
- optgetstr(bp->optdata, OBhostname,
- conf.hostname, sizeof conf.hostname);
- optgetstr(bp->optdata, OBdomainname,
- conf.domainname, sizeof conf.domainname);
+ if(optgetstr(bp->optdata, OBhostname,
+ conf.hostname, sizeof conf.hostname))
+ DEBUG("hostname=%s ", conf.hostname);
+ if(optgetstr(bp->optdata, OBdomainname,
+ conf.domainname, sizeof conf.domainname))
+ DEBUG("domainname=%s ", conf.domainname);
+ if(optgetnames(bp->optdata, ODdnsdomain,
+ conf.dnsdomain, sizeof conf.dnsdomain))
+ DEBUG("dnsdomain=%s ", conf.dnsdomain);
/* get anything else we asked for */
getoptions(bp->optdata);
@@ -679,9 +687,8 @@ optget(uchar *p, int op, int *np)
continue;
}
if(np != nil){
- if(*np > len) {
+ if(*np > len)
return 0;
- }
*np = len;
}
return p;
@@ -799,6 +806,28 @@ optgetstr(uchar *p, int op, char *s, int n)
return len;
}
+static int
+optgetnames(uchar *p, int op, char *s, int n)
+{
+ uchar buf[256];
+ int nbuf, len;
+
+ for(nbuf=0;;p+=len,nbuf+=len){
+ len = 1;
+ p = optget(p, op, &len);
+ if(p == nil)
+ break;
+ if(nbuf+len > sizeof(buf))
+ return 0;
+ memmove(buf+nbuf, p, len);
+ }
+ if((len = gnames(s, n, buf, nbuf)) < 0){
+ memset(s, 0, n);
+ return 0;
+ }
+ return len;
+}
+
int
addoption(char *opt)
{
@@ -865,7 +894,6 @@ optgetx(uchar *p, uchar opt)
case Tvec:
n = optgetvec(p, opt, vec, sizeof vec);
if(n > 0)
- /* what's %H? it's not installed */
s = smprint("%s=%.*H", o->name, n, vec);
break;
}