From d1d726db68059d73a97d03b40eb5366120e6378e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 6 May 2014 15:56:33 +0200 Subject: use getopt for command line parsing --- dyndhcpd.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/dyndhcpd.c b/dyndhcpd.c index bbbf4d7..993b3ed 100644 --- a/dyndhcpd.c +++ b/dyndhcpd.c @@ -85,33 +85,22 @@ int main(int argc, char ** argv) { printf("Starting dyndhcpd/" VERSION " (compiled: " __DATE__ ", " __TIME__ ")\n"); /* get command line options */ - for (i = 1; i < argc; i++) { - switch ((int)argv[i][0]) { - case '-': - switch ((int)argv[i][1]) { - case 'h': - fprintf(stderr, "usage: %s [-h] [-iINTERFACE] [-v]\n", argv[0]); - return EXIT_SUCCESS; - case 'v': - verbose++; - break; - case 'i': - interface = argv[i] + 2; - if (strlen(interface) == 0) { - fprintf(stderr, "No interface given!\n"); - return EXIT_FAILURE; - } - break; - default: - fprintf(stderr, "unknown option: '%s'\n", argv[i]); - return EXIT_FAILURE; + while ((i = getopt(argc, argv, "hi:v")) != -1) + switch (i) { + case 'h': + fprintf(stderr, "usage: %s [-h] -i INTERFACE [-v]\n", argv[0]); + return EXIT_SUCCESS; + case 'i': + interface = optarg; + if (strlen(interface) == 0) { + fprintf(stderr, "No interface given!\n"); + return EXIT_FAILURE; } break; - default: - fprintf(stderr, "unknown command line argument: '%s'\n", argv[i]); - return EXIT_FAILURE; + case 'v': + verbose++; + break; } - } /* bail if we are not root */ if (getuid() > 0) { -- cgit v1.2.3-70-g09d2