Be more like Windows and Linux and send our hostname in the host-name

option if none is given in the config file.  Also add #ifdefd out
support for sending a client ID based on our MAC address.

PR:		bin/94743, bin/76401
Submitted by:	Frank Behrens <frank at pinky dot sax dot de>
X-MFC after:	6.1-RELEASE
This commit is contained in:
Brooks Davis 2006-05-07 23:31:10 +00:00
parent 46d5426b1b
commit fcab8addcf
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=158353

View File

@ -1461,6 +1461,40 @@ make_discover(struct interface_info *ip, struct client_lease *lease)
ip->client->config->send_options[i].len;
options[i]->timeout = 0xFFFFFFFF;
}
/* send host name if not set via config file. */
char hostname[_POSIX_HOST_NAME_MAX+1];
if (!options[DHO_HOST_NAME]) {
if (gethostname(hostname, sizeof(hostname)) == 0) {
size_t len;
char* posDot = strchr(hostname, '.');
if (posDot != NULL)
len = posDot - hostname;
else
len = strlen(hostname);
options[DHO_HOST_NAME] = &option_elements[DHO_HOST_NAME];
options[DHO_HOST_NAME]->value = hostname;
options[DHO_HOST_NAME]->len = len;
options[DHO_HOST_NAME]->buf_size = len;
options[DHO_HOST_NAME]->timeout = 0xFFFFFFFF;
}
}
#ifdef SEND_CLIENT_IDENTIFIER
/* set unique client identifier */
char client_ident[sizeof(struct hardware)];
if (!options[DHO_DHCP_CLIENT_IDENTIFIER]) {
int hwlen = (ip->hw_address.hlen < sizeof(client_ident)-1) ?
ip->hw_address.hlen : sizeof(client_ident)-1;
client_ident[0] = ip->hw_address.htype;
memcpy(&client_ident[1], ip->hw_address.haddr, hwlen);
options[DHO_DHCP_CLIENT_IDENTIFIER] = &option_elements[DHO_DHCP_CLIENT_IDENTIFIER];
options[DHO_DHCP_CLIENT_IDENTIFIER]->value = client_ident;
options[DHO_DHCP_CLIENT_IDENTIFIER]->len = hwlen+1;
options[DHO_DHCP_CLIENT_IDENTIFIER]->buf_size = hwlen+1;
options[DHO_DHCP_CLIENT_IDENTIFIER]->timeout = 0xFFFFFFFF;
}
#endif
/* Set up the option buffer... */
ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0,
@ -1553,6 +1587,40 @@ make_request(struct interface_info *ip, struct client_lease * lease)
ip->client->config->send_options[i].len;
options[i]->timeout = 0xFFFFFFFF;
}
/* send host name if not set via config file. */
char hostname[_POSIX_HOST_NAME_MAX+1];
if (!options[DHO_HOST_NAME]) {
if (gethostname(hostname, sizeof(hostname)) == 0) {
size_t len;
char* posDot = strchr(hostname, '.');
if (posDot != NULL)
len = posDot - hostname;
else
len = strlen(hostname);
options[DHO_HOST_NAME] = &option_elements[DHO_HOST_NAME];
options[DHO_HOST_NAME]->value = hostname;
options[DHO_HOST_NAME]->len = len;
options[DHO_HOST_NAME]->buf_size = len;
options[DHO_HOST_NAME]->timeout = 0xFFFFFFFF;
}
}
#ifdef SEND_CLIENT_IDENTIFIER
/* set unique client identifier */
char client_ident[sizeof(struct hardware)];
if (!options[DHO_DHCP_CLIENT_IDENTIFIER]) {
int hwlen = (ip->hw_address.hlen < sizeof(client_ident)-1) ?
ip->hw_address.hlen : sizeof(client_ident)-1;
client_ident[0] = ip->hw_address.htype;
memcpy(&client_ident[1], ip->hw_address.haddr, hwlen);
options[DHO_DHCP_CLIENT_IDENTIFIER] = &option_elements[DHO_DHCP_CLIENT_IDENTIFIER];
options[DHO_DHCP_CLIENT_IDENTIFIER]->value = client_ident;
options[DHO_DHCP_CLIENT_IDENTIFIER]->len = hwlen+1;
options[DHO_DHCP_CLIENT_IDENTIFIER]->buf_size = hwlen+1;
options[DHO_DHCP_CLIENT_IDENTIFIER]->timeout = 0xFFFFFFFF;
}
#endif
/* Set up the option buffer... */
ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0,