]> 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:35 +0000 (12:00 +0000)
committerRoy Marples <roy@marples.name>
Mon, 26 Jan 2009 12:00:35 +0000 (12:00 +0000)
dhcp.c
dhcpcd.c
dhcpcd.h

diff --git a/dhcp.c b/dhcp.c
index 4fe389764bed8855e8a8ee5d6a8c9da42f2f27e3..d58698459a61963a1c204492cd98905e2f1718d8 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -767,6 +767,7 @@ make_message(struct dhcp_message **message,
        uint16_t sz;
        const struct dhcp_opt *opt;
        size_t len;
+       const char *hp;
 
        dhcp = xzalloc(sizeof (*dhcp));
        m = (uint8_t *)dhcp;
@@ -886,10 +887,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 (options->hostname[0]) {
                        *p++ = DHO_HOSTNAME;
-                       memcpy(p, options->hostname, options->hostname[0] + 1);
-                       p += options->hostname[0] + 1;
+                       hp = strchr(options->hostname, '.');
+                       if (hp) {
+                               *p++ = hp - options->hostname;
+                               memcpy(p, options->hostname, hp - options->hostname);
+                               p += hp - options->hostname;
+                       } else {
+                               len = strlen(options->hostname);
+                               *p++ = len;
+                               memcpy(p, options->hostname, len);
+                               p += len;
+                       }
                }
                if (options->fqdn != FQDN_DISABLE) {
                        /* IETF DHC-FQDN option (81), RFC4702 */
@@ -909,8 +923,8 @@ make_message(struct dhcp_message **message,
                        *p++ = (options->fqdn & 0x09) | 0x04;
                        *p++ = 0; /* from server for PTR RR */
                        *p++ = 0; /* from server for A RR if S=1 */
-                       ul = encode_rfc1035(options->hostname + 1, p,
-                                       options->hostname[0]);
+                       ul = encode_rfc1035(options->hostname, p,
+                                           strlen(options->hostname));
                        *lp += ul;
                        p += ul;
                }
index 58321ef77b68dd358ed92b5cc2bf77c630374acb..1626e3953661f7b4de5e6d8a7eb80a68acab8243 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -648,13 +648,12 @@ main(int argc, char **argv)
        }
 #endif
 
-       gethostname(options->hostname + 1, HOSTNAME_MAX_LEN);
+       gethostname(options->hostname, HOSTNAME_MAX_LEN);
        /* Ensure that the hostname is NULL terminated */ 
-       options->hostname[HOSTNAME_MAX_LEN + 1] = '\0';
-       if (strcmp(options->hostname + 1, "(none)") == 0 ||
-           strcmp(options->hostname + 1, "localhost") == 0)
-               options->hostname[1] = '\0';
-       *options->hostname = strlen(options->hostname + 1);
+       options->hostname[HOSTNAME_MAX_LEN] = '\0';
+       if (strcmp(options->hostname, "(none)") == 0 ||
+           strcmp(options->hostname, "localhost") == 0)
+               options->hostname[0] = '\0';
 
        while ((opt = getopt_long(argc, argv, OPTS EXTRA_OPTS,
                                  longopts, &option_index)) != -1)
index 0aeffaed9f2189ad737a68a77e9f848d46ce204e..7d9331545fc8edf704fd5749fc1ce77466d31278 100644 (file)
--- a/dhcpcd.h
+++ b/dhcpcd.h
@@ -82,7 +82,7 @@ struct options {
        char script[PATH_MAX];
        char pidfile[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];