SHA256
1
0
forked from pool/dhcp
dhcp/dhcp-send-hostname-rml.patch

105 lines
3.1 KiB
Diff

Add -H flag to specify a hostname to send to the DHCP server
client/dhclient.8 | 8 ++++++++
client/dhclient.c | 41 +++++++++++++++++++++++++++++++++++++++--
2 files changed, 47 insertions(+), 2 deletions(-)
diff -urN dhcp-3.0.3/client/dhclient.8 dhcp/client/dhclient.8
--- dhcp-3.0.3/client/dhclient.8 2006-05-04 13:06:38.000000000 -0400
+++ dhcp/client/dhclient.8 2006-05-04 13:08:33.000000000 -0400
@@ -33,6 +33,9 @@
.I port
]
[
+.B -H hostname
+]
+[
.B -d
]
[
@@ -165,6 +168,11 @@
transmit on, the client will also use a different destination port -
one greater than the specified destination port.
.PP
+The
+.B -H
+flag may be used to specify a client hostname that should be sent to
+the DHCP server.
+.PP
The DHCP client normally transmits any protocol messages it sends
before acquiring an IP address to, 255.255.255.255, the IP limited
broadcast address. For debugging purposes, it may be useful to have
diff -urN dhcp-3.0.3/client/dhclient.c dhcp/client/dhclient.c
--- dhcp-3.0.3/client/dhclient.c 2006-05-04 13:06:38.000000000 -0400
+++ dhcp/client/dhclient.c 2006-05-04 13:09:41.000000000 -0400
@@ -104,6 +104,7 @@
int no_dhclient_db = 0;
int no_dhclient_pid = 0;
int no_dhclient_script = 0;
+ char *dhclient_hostname = NULL;
char *s;
/* Make sure we have stdin, stdout and stderr. */
@@ -186,6 +187,15 @@
if (++i == argc)
usage ();
relay = argv [i];
+ } else if (!strcmp (argv [i], "-H")) {
+ if (++i == argc || !argv[i] || *(argv[i]) == '\0')
+ usage ();
+ if (strlen (argv[i]) >= DHCP_OPTION_LEN) {
+ log_error("-H option host-name string \"%s\" is too long:"
+ "maximum length is %d characters", argv[i], DHCP_OPTION_LEN-1);
+ exit(1);
+ }
+ dhclient_hostname = argv [i];
} else if (!strcmp (argv [i], "-nw")) {
nowait = 1;
} else if (!strcmp (argv [i], "-n")) {
@@ -350,6 +360,33 @@
/* Parse the dhclient.conf file. */
read_client_conf ();
+ /* If the user specified a hostname, send it here and now */
+ if ((dhclient_hostname != NULL) && (*dhclient_hostname != '\0') ) {
+ struct parse *cfile = NULL;
+ char buf[DHCP_OPTION_LEN + 40];
+ int len;
+
+ len = sprintf (buf, "send host-name \"%s\";", dhclient_hostname);
+
+ status = new_parse (&cfile, -1, buf, len, "host-name option", 0);
+
+ if (status != ISC_R_SUCCESS)
+ log_fatal ("Cannot parse dhcp-client-identifier send statement!");
+
+ for (;;) {
+ const char *val = NULL;
+ int token;
+
+ token = peek_token (&val, (unsigned *)0, cfile);
+ if (token == END_OF_FILE)
+ break;
+
+ parse_client_statement (cfile, NULL, &top_level_config);
+
+ }
+ end_parse (&cfile);
+ }
+
/* Parse the lease database. */
read_client_leases ();
@@ -487,9 +524,9 @@
log_info (url);
#ifdef EXTENDED_NEW_OPTION_INFO
- log_error ("Usage: dhclient [-1dqr] [-nwx] [-p <port>] %s",
+ log_error ("Usage: dhclient [-1dqr] [-nwx] [-H <hostname>] [-p <port>] %s",
#else
- log_error ("Usage: dhclient [-1dqr] [-nw] [-p <port>] %s",
+ log_error ("Usage: dhclient [-1dqr] [-nw] [-H <hostname>] [-p <port>] %s",
#endif
"[-s server]");
log_error (" [-cf config-file] [-lf lease-file]%s",