From: Roy Marples Date: Mon, 28 May 2007 12:15:27 +0000 (+0000) Subject: -HH sets the hostname to the full dns name looked up if we need to. X-Git-Tag: v3.2.3~247 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d6293b37c35b056d4bcc40238e8c251f68d49d6c;p=thirdparty%2Fdhcpcd.git -HH sets the hostname to the full dns name looked up if we need to. --- diff --git a/ChangeLog b/ChangeLog index 51e7cc43..392f8963 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +-HH sets the hostname to the full dns name looked up if we need to. Fix arp compilation warning on GCC-4.2.0. Enable DHCP_INFORM support via the -s option again, moving DHCP_REQUEST to the -r option. This makes us more compatible with dhcpcd-1.x and 2.x. diff --git a/configure.c b/configure.c index 6ab860ac..96ef38d2 100644 --- a/configure.c +++ b/configure.c @@ -496,7 +496,7 @@ int configure (const options_t *options, interface_t *iface, #endif /* Now we have made a resolv.conf we can obtain a hostname if we need it */ - if (options->dohostname && ! dhcp->hostname) { + if (options->dohostname && ! dhcp->hostname) { union { struct sockaddr sa; struct sockaddr_in sin; @@ -524,8 +524,31 @@ int configure (const options_t *options, interface_t *iface, freeaddrinfo (res); addr[0] = '\0'; logger (LOG_ERR, "malicious PTR record detected"); - } else if (*addr) + } else if (*addr) { + if (options->dohostname == 1) { + /* Strip out the domain if it matches */ + char *p = strchr (addr, '.'); + if (p) { + p++; + if (*p && dhcp->dnssearch) { + char *s = xstrdup (dhcp->dnssearch); + char *sp = s; + char *t; + + while ((t = strsep (&sp, " "))) + if (strcmp (t, p) == 0) { + *--p = '\0'; + break; + } + free (s); + } else if (dhcp->dnsdomain) { + if (strcmp (dhcp->dnsdomain, p) == 0) + *--p = '\0'; + } + } + } strlcpy (newhostname, addr, sizeof (newhostname)); + } } } diff --git a/dhcpcd.8 b/dhcpcd.8 index 747e810a..e3d5c183 100644 --- a/dhcpcd.8 +++ b/dhcpcd.8 @@ -196,7 +196,9 @@ By default will NOT set hostname of the host to the hostname option received from DHCP server unless the current hostname is blank, (none) or localhost. If no hostname is returned by the DHCP server then we attempt -to lookup the hostname via DNS. +to lookup the hostname via DNS. If we are given a DNS domain in the DHCP +message then we strip the matching part from the looked up hostname unless +told to by -HH. .TP .BI \-F \ none | ptr | both Forces diff --git a/dhcpcd.c b/dhcpcd.c index 372a95a7..81fd703c 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -297,7 +297,7 @@ int main(int argc, char **argv) options.dogateway = false; break; case 'H': - options.dohostname = true; + options.dohostname++; break; case 'I': if (optarg) { diff --git a/dhcpcd.h b/dhcpcd.h index 1902cb0a..b3a08d6d 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -54,7 +54,7 @@ typedef struct options_t { bool dodns; bool dodomainname; bool dogateway; - bool dohostname; + int dohostname; bool domtu; bool donis; bool dontp;