]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
-HH sets the hostname to the full dns name looked up if we need to.
authorRoy Marples <roy@marples.name>
Mon, 28 May 2007 12:15:27 +0000 (12:15 +0000)
committerRoy Marples <roy@marples.name>
Mon, 28 May 2007 12:15:27 +0000 (12:15 +0000)
ChangeLog
configure.c
dhcpcd.8
dhcpcd.c
dhcpcd.h

index 51e7cc4370e2ea5c5d7080f633bdae11715d80a1..392f8963dd62a24c74deb71d8096f1108a8a7516 100644 (file)
--- 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.
index 6ab860ac4a2421d636d986839ca0d3908a32ce05..96ef38d2105d4409baa121fcb5350a76682de1b1 100644 (file)
@@ -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));
+                       }
                }
        }
 
index 747e810a1246cffc9a0260ce75a722f6a5ca99c2..e3d5c183f4908ff2e93104aadc67c7bb96e63197 100644 (file)
--- 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
index 372a95a7ac160d9b6debf7c01655791eefb878b1..81fd703cabb2ab2533b5fb4cf1eb6bee406baa24 100644 (file)
--- 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) {
index 1902cb0a07f830743d2ce010340319f5eb69d6f2..b3a08d6d4803ecec4918c85eb4729829c016592c 100644 (file)
--- 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;