changeset 19:d1c15501fd5e draft

Send the current hostname by default.
author Roy Marples <roy@marples.name>
date Wed, 06 Dec 2006 09:37:15 +0000
parents a43748f6c97d
children 3dfa5666d2a6
files ChangeLog configure.c dhcp.c dhcpcd.8 dhcpcd.c dhcpcd.h
diffstat 6 files changed, 21 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Dec 05 10:12:50 2006 +0000
+++ b/ChangeLog	Wed Dec 06 09:37:15 2006 +0000
@@ -1,3 +1,6 @@
+Send the hostname by default unless null, (none) or localhost.
+This can be overridden by using a an empty option for -h (-h '').
+
 dhcpcd-3.0.3
 NIS setup (yp.conf / domainname) works again.
 Send hostname/fqdn in DISCOVER and INFORM messages too.
--- a/configure.c	Tue Dec 05 10:12:50 2006 +0000
+++ b/configure.c	Wed Dec 06 09:37:15 2006 +0000
@@ -520,8 +520,11 @@
       if (dhcp->hostname)
 	strcpy (newhostname, dhcp->hostname); 
 
-      sethostname (newhostname, strlen (newhostname));
-      logger (LOG_INFO, "setting hostname to `%s'", newhostname);
+      if (*newhostname)
+	{
+	  logger (LOG_INFO, "setting hostname to `%s'", newhostname);
+	  sethostname (newhostname, strlen (newhostname));
+	}
     }
 
   write_info (iface, dhcp);
--- a/dhcp.c	Tue Dec 05 10:12:50 2006 +0000
+++ b/dhcp.c	Wed Dec 06 09:37:15 2006 +0000
@@ -186,7 +186,7 @@
 
       *n_params = p - n_params - 1;
 
-      if (options->hostname) 
+      if (*options->hostname) 
 	{
 	  if (options->fqdn == FQDN_DISABLE)
 	    {
--- a/dhcpcd.8	Tue Dec 05 10:12:50 2006 +0000
+++ b/dhcpcd.8	Wed Dec 06 09:37:15 2006 +0000
@@ -1,6 +1,6 @@
 .\" $Id$
 .\"
-.TH dhcpcd 8 "30 November 2006" "dhcpcd 3.0"
+.TH dhcpcd 8 "06 December 2006" "dhcpcd 3.0"
 
 .SH NAME
 dhcpcd \- DHCP client daemon
@@ -70,6 +70,7 @@
 field containing a specific string in the DHCP messages from clients.
 When combined with the -F switch, specifies the string used for the
 FQDN option field instead of the hostname option field.
+We send the current hostname by default. To send no hostname, use -h ''.
 .TP
 .BI \-i \ vendorClassID
 Specifies the vendor class identifier string.
--- a/dhcpcd.c	Tue Dec 05 10:12:50 2006 +0000
+++ b/dhcpcd.c	Wed Dec 06 09:37:15 2006 +0000
@@ -118,6 +118,10 @@
   options.donis = true;
   options.dontp = true;
   options.dogateway = true;
+  gethostname (options.hostname, sizeof (options.hostname));
+  if (strcmp (options.hostname, "(none)") == 0 ||
+      strcmp (options.hostname, "localhost") == 0)
+    memset (options.hostname, 0, sizeof (options.hostname));
   options.timeout = DEFAULT_TIMEOUT;
 
   int doversion = 0;
@@ -182,7 +186,7 @@
 	    exit (EXIT_FAILURE);
 	  }
 	else
-	  options.hostname = optarg;
+	  strcpy (options.hostname, optarg);
 	break;
       case 'i':
 	if (strlen(optarg) > CLASS_ID_MAX_LEN)
@@ -307,7 +311,7 @@
 		  argv[optind], IF_NAMESIZE);
 	  exit (EXIT_FAILURE);
 	}
-      options.interface = argv[optind];
+      strcpy (options.interface, argv[optind]);
     }
   else
     {
--- a/dhcpcd.h	Tue Dec 05 10:12:50 2006 +0000
+++ b/dhcpcd.h	Wed Dec 06 09:37:15 2006 +0000
@@ -23,6 +23,7 @@
 #ifdef __linux__
 #include <linux/limits.h>
 #endif
+#include <net/if.h>
 #include <netinet/in.h>
 #include <limits.h>
 #include <stdbool.h>
@@ -35,12 +36,12 @@
 
 #define CLASS_ID_MAX_LEN	48
 #define CLIENT_ID_MAX_LEN	48
-#define HOSTNAME_MAX_LEN	64
+#define HOSTNAME_MAX_LEN	255	
 #define USERCLASS_MAX_LEN	255	
 
 typedef struct options_t {
-  char *interface;
-  char *hostname;
+  char interface[IF_NAMESIZE];
+  char hostname[HOSTNAME_MAX_LEN];
   int fqdn;
   char classid[CLASS_ID_MAX_LEN];
   char clientid[CLIENT_ID_MAX_LEN];