]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
We should only send short hostnames as qualfied ones confuse ISC DHCP server. If...
authorRoy Marples <roy@marples.name>
Mon, 26 Jan 2009 12:00:01 +0000 (12:00 +0000)
committerRoy Marples <roy@marples.name>
Mon, 26 Jan 2009 12:00:01 +0000 (12:00 +0000)
dhcp.c
if-options.c
if-options.h

diff --git a/dhcp.c b/dhcp.c
index a1029c931358f5f2952a4afe5723a12e8c9a5312..b157c6f8b53da428ea12bd4852f05b8b6ac727ac 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -766,6 +766,7 @@ make_message(struct dhcp_message **message,
        uint32_t ul;
        uint16_t sz;
        size_t len;
+       const char *hp;
        const struct dhcp_opt *opt;
        const struct if_options *ifo = iface->state->options;
        const struct dhcp_lease *lease = &iface->state->lease;
@@ -889,10 +890,23 @@ make_message(struct dhcp_message **message,
                        }
                }
 
+               /* Regardless of RFC2132, we should always send a hostname
+                * upto the first dot (the short hostname) as otherwise
+                * confuses some DHCP servers when updating DNS.
+                * The FQDN option should be used if a FQDN is required. */
                if (ifo->hostname[0]) {
                        *p++ = DHO_HOSTNAME;
-                       memcpy(p, ifo->hostname, ifo->hostname[0] + 1);
-                       p += ifo->hostname[0] + 1;
+                       hp = strchr(ifo->hostname, '.');
+                       if (hp) {
+                               *p++ = hp - ifo->hostname;
+                               memcpy(p, ifo->hostname, hp - ifo->hostname);
+                               p += hp - ifo->hostname;
+                       } else {
+                               len = strlen(ifo->hostname);
+                               *p++ = len;
+                               memcpy(p, ifo->hostname, len);
+                               p += len;
+                       }
                }
                if (ifo->fqdn != FQDN_DISABLE) {
                        /* IETF DHC-FQDN option (81), RFC4702 */
@@ -912,8 +926,8 @@ make_message(struct dhcp_message **message,
                        *p++ = (ifo->fqdn & 0x09) | 0x04;
                        *p++ = 0; /* from server for PTR RR */
                        *p++ = 0; /* from server for A RR if S=1 */
-                       ul = encode_rfc1035(ifo->hostname + 1, p,
-                                           ifo->hostname[0]);
+                       ul = encode_rfc1035(ifo->hostname, p,
+                                           strlen(ifo->hostname));
                        *lp += ul;
                        p += ul;
                }
index e8eb5186a972a86cb560251b626da2dc909c29aa..36dd1a0d9110ed50d4b09fbdac4f663e14272b75 100644 (file)
@@ -676,13 +676,12 @@ read_config(const char *file, const char *ifname, const char *ssid)
        ifo->timeout = DEFAULT_TIMEOUT;
        ifo->reboot = DEFAULT_REBOOT;
        ifo->metric = -1;
-       gethostname(ifo->hostname + 1, HOSTNAME_MAX_LEN);
+       gethostname(ifo->hostname, HOSTNAME_MAX_LEN);
        /* Ensure that the hostname is NULL terminated */
-       ifo->hostname[HOSTNAME_MAX_LEN + 1] = '\0';
-       if (strcmp(ifo->hostname + 1, "(none)") == 0 ||
-           strcmp(ifo->hostname + 1, "localhost") == 0)
-               ifo->hostname[1] = '\0';
-       *ifo->hostname = strlen(ifo->hostname + 1);
+       ifo->hostname[HOSTNAME_MAX_LEN] = '\0';
+       if (strcmp(ifo->hostname, "(none)") == 0 ||
+           strcmp(ifo->hostname, "localhost") == 0)
+               ifo->hostname[0] = '\0';
        strlcpy(ifo->script, SCRIPT, sizeof(ifo->script));
        ifo->vendorclassid[0] = snprintf((char *)ifo->vendorclassid + 1,
                                             VENDORCLASSID_MAX_LEN,
index 5a8b8aafa9d111a1cf4ad57311b7f5923d2c55ef..02f5f2dc83ccc79e4ceb0a995deaf2062b69990d 100644 (file)
@@ -88,8 +88,8 @@ struct if_options {
 
        char **environ;
        char script[PATH_MAX];
-
-       char hostname[HOSTNAME_MAX_LEN + 2];
+       
+       char hostname[HOSTNAME_MAX_LEN + 1]; /* We don't store the lenth */
        int fqdn;
        uint8_t vendorclassid[VENDORCLASSID_MAX_LEN + 2];
        char clientid[CLIENTID_MAX_LEN + 2];