From: Roy Marples Date: Wed, 6 Dec 2006 09:37:15 +0000 (+0000) Subject: Send the current hostname by default. X-Git-Tag: v3.2.3~355 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=71b1afde0f2887daea87ef6f2da56df7c8819ef6;p=thirdparty%2Fdhcpcd.git Send the current hostname by default. --- diff --git a/ChangeLog b/ChangeLog index 7165c3ad..8253a045 100644 --- 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. diff --git a/configure.c b/configure.c index 3d3441cc..478c029d 100644 --- a/configure.c +++ b/configure.c @@ -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 fbf5389d..b7bab52a 100644 --- 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) { diff --git a/dhcpcd.8 b/dhcpcd.8 index 7ace8b20..07aae5c1 100644 --- 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. diff --git a/dhcpcd.c b/dhcpcd.c index 10cd388b..150dd818 100644 --- 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 { diff --git a/dhcpcd.h b/dhcpcd.h index 907e9d2d..623de7f4 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -23,6 +23,7 @@ #ifdef __linux__ #include #endif +#include #include #include #include @@ -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];