summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2015-07-03 14:31:48 +0200
committerGravatar Christian Hesse <mail@eworm.de>2015-07-03 14:31:48 +0200
commita76cf581dde260fabd803465dc413648d419dcf7 (patch)
tree647042b497aa299bc88151dbcf3285b76e4b8b9b
parente030b496f5c1e99c1d3090aaadeb0ba9badafc49 (diff)
downloaddyndhcpd-a76cf581dde260fabd803465dc413648d419dcf7.tar.gz
dyndhcpd-a76cf581dde260fabd803465dc413648d419dcf7.tar.zst
add --version option
-rw-r--r--dyndhcpd.c22
-rw-r--r--dyndhcpd.h2
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];