summaryrefslogtreecommitdiffstats
path: root/sbin/dhclient
diff options
context:
space:
mode:
authorbrooks <brooks@FreeBSD.org>2006-05-07 23:31:10 +0000
committerbrooks <brooks@FreeBSD.org>2006-05-07 23:31:10 +0000
commit74f46cfedd6581aa13fc1d188df5bd6227b85bd1 (patch)
tree7a92dce4294b5fd3fe355c01d01361ce7ea6700a /sbin/dhclient
parent141ad138acae09682e521dd9b6e04c9e0f0e75de (diff)
downloadFreeBSD-src-74f46cfedd6581aa13fc1d188df5bd6227b85bd1.zip
FreeBSD-src-74f46cfedd6581aa13fc1d188df5bd6227b85bd1.tar.gz
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
Diffstat (limited to 'sbin/dhclient')
-rw-r--r--sbin/dhclient/dhclient.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 40e68af..9c691f8 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -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,
OpenPOWER on IntegriCloud