--HH sets the hostname to the full dns name looked up if we need to.
+We now have 6 hostname options, which should satisfy everyone.
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.
#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 || options->dohostname > 3)) {
union {
struct sockaddr sa;
struct sockaddr_in sin;
addr[0] = '\0';
logger (LOG_ERR, "malicious PTR record detected");
} 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) {
+ char *p = strchr (addr, '.');
+ if (p) {
+ switch (options->dohostname) {
+ case 1: /* -H */
+ case 4: /* -HHHH */
+ break;
+ case 2: /* -HH */
+ case 5: /* -HHHHH */
+ /* Strip out the domain if it matches */
+ 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';
- break;
- }
- free (s);
- } else if (dhcp->dnsdomain) {
- if (strcmp (dhcp->dnsdomain, p) == 0)
- *--p = '\0';
- }
+ }
+ break;
+ case 3: /* -HHH */
+ case 6: /* -HHHHHH */
+ /* Just strip the domain */
+ *p = '\0';
+ break;
+ default: /* Too many H! */
+ break;
}
}
strlcpy (newhostname, addr, sizeof (newhostname));
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. 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.
+to lookup the hostname via DNS.
+More -H's control what we do with the FQDN returned by DNS.
+.IP
+.BI \-H
+set hostname to the full FQDN
+.br
+.BI \-HH
+strip the domain if it matches a given domain in our DHCP message
+.br
+.BI \-HHH
+strip the domain regardless
+.br
+.BI \-HHHH
+force hostname lookup even if given a hostname in our DHCP message
+.br
+.BI \-HHHHH
+same as above, but strip the domain if it matches
+.br
+.BI \-HHHHHH
+same as above, but strip the domain regardless
.TP
.BI \-F \ none | ptr | both
Forces