From 121e4d1510fc02a0459e89e925fb92e6edd0e070 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Fri, 24 Dec 2010 10:44:06 -0500 Subject: [PATCH] Fix --hostname option. --- ndhc/config.h | 4 ++-- ndhc/ndhc.c | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ndhc/config.h b/ndhc/config.h index 60ddf04..7af66bc 100644 --- a/ndhc/config.h +++ b/ndhc/config.h @@ -42,8 +42,8 @@ struct client_config_t { char abort_if_no_lease; /* Abort if no lease */ char background_if_no_lease; /* Fork to background if no lease */ char *interface; /* The name of the interface to use */ - unsigned char *clientid; /* Optional client id to use */ - unsigned char *hostname; /* Optional hostname to use */ + unsigned char *clientid; /* Optional client id to use (unterminated) */ + unsigned char *hostname; /* Optional hostname to use (unterminated) */ int ifindex; /* Index number of the interface to use */ unsigned char arp[6]; /* Our arp address */ }; diff --git a/ndhc/ndhc.c b/ndhc/ndhc.c index 811fe15..20f0588 100644 --- a/ndhc/ndhc.c +++ b/ndhc/ndhc.c @@ -326,14 +326,13 @@ int main(int argc, char **argv) len = strlen(optarg) > 64 ? 64 : strlen(optarg); if (client_config.hostname) free(client_config.hostname); - client_config.hostname = xmalloc(len + 1); + client_config.hostname = xmalloc(len + 3); client_config.hostname[OPT_CODE] = DHCP_HOST_NAME; - client_config.hostname[OPT_LEN] = len; - strlcpy((char*)client_config.hostname + OPT_DATA, optarg, - len + 1 - (OPT_DATA - OPT_CODE)); + client_config.hostname[OPT_LEN] = len + 1; + memcpy(client_config.hostname + 3, optarg, len); break; case 'i': - client_config.interface = optarg; + client_config.interface = optarg; break; case 'n': client_config.abort_if_no_lease = 1;