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;
}
}
+ /* 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 */
*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;
}
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,