diff options
author | Brooks Davis <brooks@FreeBSD.org> | 2006-05-07 23:31:10 +0000 |
---|---|---|
committer | Brooks Davis <brooks@FreeBSD.org> | 2006-05-07 23:31:10 +0000 |
commit | fcab8addcfb6a59f989f573ff300ce6a62d4186a (patch) | |
tree | 7a92dce4294b5fd3fe355c01d01361ce7ea6700a /sbin/dhclient/dhclient.c | |
parent | 46d5426b1b3f2ebf9965c33639918830c84a61d0 (diff) | |
download | src-test2-fcab8addcfb6a59f989f573ff300ce6a62d4186a.tar.gz src-test2-fcab8addcfb6a59f989f573ff300ce6a62d4186a.zip |
Notes
Diffstat (limited to 'sbin/dhclient/dhclient.c')
-rw-r--r-- | sbin/dhclient/dhclient.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 40e68af83f89..9c691f89bb47 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, |