{"fqdn", optional_argument, NULL, 'F'},
{"nogateway", no_argument, NULL, 'G'},
{"sethostname", no_argument, NULL, 'H'},
- {"clientid", required_argument, NULL, 'I'},
+ {"clientid", optional_argument, NULL, 'I'},
{"nomtu", no_argument, NULL, 'M'},
{"nontp", no_argument, NULL, 'N'},
{"nodns", no_argument, NULL, 'R'},
options.daemonise = true;
options.timeout = DEFAULT_TIMEOUT;
- while ((ch = getopt_long(argc, argv, "ac:dh:i:kl:m:nps:t:u:EF:GHI:MNRY", longopts,
+ while ((ch = getopt_long(argc, argv, "ac:dh:i:kl:m:nps:t:u:EF::GHI::MNRY", longopts,
&option_index)) != -1)
+ {
switch (ch) {
case 0:
if (longopts[option_index].flag)
options.dolastlease = true;
break;
case 'F':
- if (strncmp (optarg, "none", strlen (optarg)) == 0)
- options.fqdn = FQDN_NONE;
- else if (strncmp (optarg, "ptr", strlen (optarg)) == 0)
- options.fqdn = FQDN_PTR;
- else if (strncmp (optarg, "both", strlen (optarg)) == 0)
+ if (optarg) {
+ if (strncmp (optarg, "none", strlen (optarg)) == 0)
+ options.fqdn = FQDN_NONE;
+ else if (strncmp (optarg, "ptr", strlen (optarg)) == 0)
+ options.fqdn = FQDN_PTR;
+ else if (strncmp (optarg, "both", strlen (optarg)) == 0)
+ options.fqdn = FQDN_BOTH;
+ else {
+ logger (LOG_ERR, "invalid value `%s' for FQDN", optarg);
+ exit (EXIT_FAILURE);
+ }
+ } else
options.fqdn = FQDN_BOTH;
- else {
- logger (LOG_ERR, "invalid value `%s' for FQDN", optarg);
- exit (EXIT_FAILURE);
- }
break;
case 'G':
options.dogateway = false;
options.dohostname = true;
break;
case 'I':
- if (strlen (optarg) > CLIENT_ID_MAX_LEN) {
- logger (LOG_ERR, "`%s' is too long for ClientID, max is %d",
- optarg, CLIENT_ID_MAX_LEN);
- exit (EXIT_FAILURE);
+ if (optarg && strlen(optarg) > 0) {
+ if (strlen (optarg) > CLIENT_ID_MAX_LEN) {
+ logger (LOG_ERR, "`%s' is too long for ClientID, max is %d",
+ optarg, CLIENT_ID_MAX_LEN);
+ exit (EXIT_FAILURE);
+ } else
+ strlcpy (options.clientid, optarg, sizeof (options.clientid));
+ options.clientid_len = strlen (options.clientid);
} else
- strlcpy (options.clientid, optarg, sizeof (options.clientid));
+ options.clientid_len = -1;
break;
case 'M':
options.domtu = false;
usage ();
exit (EXIT_FAILURE);
}
-
+ }
if (doversion)
printf (""PACKAGE" "VERSION"\n");
fprintf (f, "REBINDTIME='%u'\n", dhcp->rebindtime);
fprintf (f, "INTERFACE='%s'\n", iface->name);
fprintf (f, "CLASSID='%s'\n", cleanmetas (options->classid));
- if (options->clientid[0])
- fprintf (f, "CLIENTID='%s'\n", cleanmetas (options->clientid));
+ if (options->clientid_len > 0)
+ fprintf (f, "CLIENTID='00:%s'\n", cleanmetas (options->clientid));
#ifdef ENABLE_DUID
- else if (iface->duid_length > 0) {
+ else if (iface->duid_length > 0 && options->clientid_len != -1) {
unsigned char duid[256];
unsigned char *p = duid;
uint32_t ul;
+ *p++ = 255;
+
/* IAID is 4 bytes, so if the interface name is 4 bytes then use it */
if (strlen (iface->name) == 4) {
memcpy (p, iface->name, 4);
}
#endif
else
- fprintf (f, "CLIENTID='%s'\n", hwaddr_ntoa (iface->hwaddr, iface->hwlen));
+ fprintf (f, "CLIENTID='%.2X:%s'\n", iface->family,
+ hwaddr_ntoa (iface->hwaddr, iface->hwlen));
fprintf (f, "DHCPCHADDR='%s'\n", hwaddr_ntoa (iface->hwaddr, iface->hwlen));
#ifdef ENABLE_INFO_COMPAT