uint16_t sz;
const struct dhcp_opt *opt;
size_t len;
+ const char *hp;
dhcp = xzalloc(sizeof (*dhcp));
m = (uint8_t *)dhcp;
}
}
+ /* 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 */
*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;
}
}
#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)