From: Roy Marples Date: Mon, 14 May 2007 22:12:01 +0000 (+0000) Subject: Stop using optional arguments, use '' instead so we're more compatible with dhcpcd... X-Git-Tag: v3.2.3~253 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=49f0bcb56c75082f0ac105fd70d93a0da3cd61dc;p=thirdparty%2Fdhcpcd.git Stop using optional arguments, use '' instead so we're more compatible with dhcpcd-1.x and 2.x. Install /var/lib if it doesn't exist --- diff --git a/Makefile b/Makefile index b5c2e744..a55b1f25 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,7 @@ INSTALL ?= install DESTDIR = SBINDIR = $(DESTDIR)/sbin MANDIR = $(DESTDIR)/usr/share/man +LIBDIR = $(DESTDIR)/var/lib SBIN_TARGETS = dhcpcd MAN8_TARGETS = dhcpcd.8 @@ -67,7 +68,8 @@ install: $(TARGET) $(INSTALL) -m 0755 -d $(SBINDIR) $(INSTALL) -m 0755 $(SBIN_TARGETS) $(SBINDIR) $(INSTALL) -m 0755 -d $(MANDIR)/man8 - $(INSTALL) -m 0755 $(MAN8_TARGETS) $(MANDIR)/man8 + $(INSTALL) -m 0644 $(MAN8_TARGETS) $(MANDIR)/man8 + $(INSTALL) -m 0755 -d $(LIBDIR) clean: rm -f $(TARGET) $(dhcpcd_H) *.o *~ *.core *.bz2 diff --git a/dhcpcd.c b/dhcpcd.c index 43768a88..f6d2a497 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -81,7 +81,7 @@ static void usage () { printf ("usage: "PACKAGE" [-adknpEGHMNRSY] [-c script] [-h hostame] [-i classID]\n" " [-l leasetime] [-m metric] [-s ipaddress] [-t timeout]\n" - " [-u userclass] [-F [none | ptr | both]] [-I [clientID]]\n"); + " [-u userclass] [-F none | ptr | both] [-I clientID]\n"); } int main(int argc, char **argv) @@ -113,10 +113,10 @@ int main(int argc, char **argv) {"timeout", required_argument, NULL, 't'}, {"userclass", required_argument, NULL, 'u'}, {"lastlease", no_argument, NULL, 'E'}, - {"fqdn", optional_argument, NULL, 'F'}, + {"fqdn", required_argument, NULL, 'F'}, {"nogateway", no_argument, NULL, 'G'}, {"sethostname", no_argument, NULL, 'H'}, - {"clientid", optional_argument, NULL, 'I'}, + {"clientid", required_argument, NULL, 'I'}, {"nomtu", no_argument, NULL, 'M'}, {"nontp", no_argument, NULL, 'N'}, {"nodns", no_argument, NULL, 'R'}, @@ -147,7 +147,7 @@ int main(int argc, char **argv) options.doinform = false; options.timeout = DEFAULT_TIMEOUT; - while ((opt = getopt_long(argc, argv, "ac:dh:i:kl:m:nps::t:u:EF::GHI::MNRSY", + while ((opt = getopt_long(argc, argv, "ac:dh:i:kl:m:nps:t:u:EF:GHI:MNRSY", longopts, &option_index)) != -1) { switch (opt) { @@ -212,7 +212,9 @@ int main(int argc, char **argv) options.persistent = true; break; case 's': - if (! inet_aton (optarg, &options.requestaddress)) { + if (strlen (optarg) == 0) + options.requestaddress.s_addr = 0; + else if (! inet_aton (optarg, &options.requestaddress)) { logger (LOG_ERR, "`%s' is not a valid IP address", optarg); exit (EXIT_FAILURE); } @@ -244,19 +246,16 @@ int main(int argc, char **argv) options.dolastlease = true; break; case 'F': - 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 + 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); + } break; case 'G': options.dogateway = false; @@ -265,15 +264,15 @@ int main(int argc, char **argv) options.dohostname = true; break; case 'I': - 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 + 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); + } + strlcpy (options.clientid, optarg, sizeof (options.clientid)); + options.clientid_len = strlen (options.clientid); + /* empty string disabled duid */ + if (options.clientid_len == 0) options.clientid_len = -1; break; case 'M':