From a76cf581dde260fabd803465dc413648d419dcf7 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 3 Jul 2015 14:31:48 +0200 Subject: add --version option --- dyndhcpd.c | 22 ++++++++++++++++++---- dyndhcpd.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/dyndhcpd.c b/dyndhcpd.c index 93dd225..457e9f3 100644 --- a/dyndhcpd.c +++ b/dyndhcpd.c @@ -7,13 +7,14 @@ #include "dyndhcpd.h" -const static char optstring[] = "c:hi:v"; +const static char optstring[] = "c:hi:vV"; const static struct option options_long[] = { /* name has_arg flag val */ { "config", required_argument, NULL, 'c' }, { "help", no_argument, NULL, 'h' }, { "interface", required_argument, NULL, 'i' }, { "verbose", no_argument, NULL, 'v' }, + { "version", no_argument, NULL, 'V' }, { 0, 0, 0, 0 } }; @@ -54,7 +55,7 @@ int main(int argc, char ** argv) { char * pidfile = NULL, * leasesfile = NULL; - printf("Starting dyndhcpd/" VERSION " (compiled: " __DATE__ ", " __TIME__ ")\n"); + unsigned int version = 0, help = 0; /* get command line options */ while ((i = getopt_long(argc, argv, optstring, options_long, NULL)) != -1) @@ -67,8 +68,8 @@ int main(int argc, char ** argv) { } break; case 'h': - fprintf(stderr, "usage: %s [-c config] [-h] -i INTERFACE [-v]\n", argv[0]); - return EXIT_SUCCESS; + help++; + break; case 'i': interface = optarg; if (strlen(interface) == 0) { @@ -79,8 +80,21 @@ int main(int argc, char ** argv) { case 'v': verbose++; break; + case 'V': + verbose++; + version++; + break; } + if (verbose > 0) + printf("%s: %s v%s (compiled: " __DATE__ ", " __TIME__ ")\n", argv[0], PROGNAME, VERSION); + + if (help > 0) + fprintf(stderr, "usage: %s [-c config] [-h] -i INTERFACE [-v] [-V]\n", argv[0]); + + if (version > 0 || help > 0) + return EXIT_SUCCESS; + /* bail if we are not root */ if (getuid() > 0) { fprintf(stderr, "You need to be root!\n"); diff --git a/dyndhcpd.h b/dyndhcpd.h index 1f01abf..f26c6bf 100644 --- a/dyndhcpd.h +++ b/dyndhcpd.h @@ -24,6 +24,8 @@ #include "config.h" #include "version.h" +#define PROGNAME "dyndhcpd" + struct address { struct in_addr i; char c[INET_ADDRSTRLEN]; -- cgit v1.2.3-70-g09d2