diff options
author | Christian Hesse <mail@eworm.de> | 2015-07-03 14:31:48 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2015-07-03 14:31:48 +0200 |
commit | a76cf581dde260fabd803465dc413648d419dcf7 (patch) | |
tree | 647042b497aa299bc88151dbcf3285b76e4b8b9b | |
parent | e030b496f5c1e99c1d3090aaadeb0ba9badafc49 (diff) | |
download | dyndhcpd-a76cf581dde260fabd803465dc413648d419dcf7.tar.gz dyndhcpd-a76cf581dde260fabd803465dc413648d419dcf7.tar.zst |
add --version option
-rw-r--r-- | dyndhcpd.c | 22 | ||||
-rw-r--r-- | dyndhcpd.h | 2 |
2 files changed, 20 insertions, 4 deletions
@@ -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"); @@ -24,6 +24,8 @@ #include "config.h" #include "version.h" +#define PROGNAME "dyndhcpd" + struct address { struct in_addr i; char c[INET_ADDRSTRLEN]; |