]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Send the current hostname by default.
authorRoy Marples <roy@marples.name>
Wed, 6 Dec 2006 09:37:15 +0000 (09:37 +0000)
committerRoy Marples <roy@marples.name>
Wed, 6 Dec 2006 09:37:15 +0000 (09:37 +0000)
ChangeLog
configure.c
dhcp.c
dhcpcd.8
dhcpcd.c
dhcpcd.h

index 7165c3ade8ddb9cb8130be2f6e52efb4d74abf1b..8253a04590091c84a2dbcf5d01e4830d3e5e0396 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index 3d3441ccc58c7b1bb44c3381ce44885221751f5d..478c029db1417bd77e39b9b8ec5e29197ae33f2f 100644 (file)
@@ -520,8 +520,11 @@ int configure (options_t *options, interface_t *iface, dhcp_t *dhcp)
       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);
diff --git a/dhcp.c b/dhcp.c
index fbf5389d464345d99a00afec021ee5454e4ae58f..b7bab52a06c69d9faa3ae9699107bcf8cc34decc 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -186,7 +186,7 @@ size_t send_message (interface_t *iface, dhcp_t *dhcp,
 
       *n_params = p - n_params - 1;
 
-      if (options->hostname) 
+      if (*options->hostname) 
        {
          if (options->fqdn == FQDN_DISABLE)
            {
index 7ace8b20e6d4c0d84b358ed7df3c8d15938c5cff..07aae5c137cedb98229f323a027ba2c6fc37d55a 100644 (file)
--- a/dhcpcd.8
+++ b/dhcpcd.8
@@ -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 @@ sends DHCP messages. Some DHCP servers, notably those used by
 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.
index 10cd388bbc3afcd1db229b519ea6d3d403fcdf42..150dd8185d49f95398a541852604dabf40a7982b 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -118,6 +118,10 @@ int main(int argc, char **argv)
   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 @@ int main(int argc, char **argv)
            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 @@ int main(int argc, char **argv)
                  argv[optind], IF_NAMESIZE);
          exit (EXIT_FAILURE);
        }
-      options.interface = argv[optind];
+      strcpy (options.interface, argv[optind]);
     }
   else
     {
index 907e9d2db61789d669510b6f87c88c3f629c9463..623de7f432ba13ac85434fdb193e30a4b58b312a 100644 (file)
--- a/dhcpcd.h
+++ b/dhcpcd.h
@@ -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>
 
 #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];