Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Mar 2006 16:02:17 +0100
From:      "Frank Behrens" <frank@pinky.sax.de>
To:        freebsd-hackers@freebsd.org
Subject:   [RFE] dhclient(8) should send hostname
Message-ID:  <200603171502.k2HF2IV3086523@pinky.frank-behrens.de>

index | next in thread | raw e-mail

[-- Attachment #1 --]
Hi,

I tried to setup a new FreeBSD 6.1-BETA2 client and enabled in 
sysinstall DHCP configuration for the interface. It was no problem 
and the system runs fine.

But then I was surprised that my nameserver 
FreeBSD 6.1-PRERELEASE-200602270917 with BIND9 and
"Internet Systems Consortium DHCP Server V3.0.3"
did not know the newly connected system, but a simple win98 notebook 
is immediately visible in DNS.

I found that the dhclient does not send a hostname by default to the 
server, so the server does not know the name. Of course you can enter 
a "send host-name "xxx"" in dhclient.conf, but this makes the setup 
more complicated. 

I propose a change, that dhclient sends always the current hostname 
to the server, the value can be overwritten in dhclient.conf. I see 
no negative impact, because the server has always the possibility to 
reject the name and to choose another one. It would simplify the 
setup and lead to the same behaviour as in other (operating) systems.
A possible (I'm sure not the best) solution I appended as attachment. 

If there are no objections from this list I will create a PR, but 
from my earlier experiences a PR without discussion is in many cases 
useless.

Regards,
   Frank
-- 
Frank Behrens, Osterwieck, Germany
PGP-key 0x5B7C47ED on public servers available.


[-- Attachment #2 --]
Index: dhclient.c
===================================================================
RCS file: /data/freebsd/src/sbin/dhclient/dhclient.c,v
retrieving revision 1.6.2.4
diff -u -r1.6.2.4 dhclient.c
--- dhclient.c	24 Jan 2006 05:59:27 -0000	1.6.2.4
+++ dhclient.c	17 Mar 2006 14:38:17 -0000
@@ -54,6 +54,8 @@
  */
 
 #include <sys/cdefs.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
 __FBSDID("$FreeBSD: src/sbin/dhclient/dhclient.c,v 1.6.2.4 2006/01/24 05:59:27 brooks Exp $");
 
 #include "dhcpd.h"
@@ -1553,6 +1555,23 @@
 			    ip->client->config->send_options[i].len;
 			options[i]->timeout = 0xFFFFFFFF;
 		}
+		
+	/* send host name if not set via config file. */
+	char hostname[50];
+	size_t len = sizeof(hostname);
+	if (!options[DHO_HOST_NAME]) {
+		if (sysctlbyname("kern.hostname", hostname, &len, NULL, 0) == 0) {
+			len--;		/* count not trailing \0 */
+			char* posDot = strchr(hostname, '.');
+			if (posDot != NULL)
+				len = posDot - 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;
+		}
+	}
 
 	/* Set up the option buffer... */
 	ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0,
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200603171502.k2HF2IV3086523>