aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2014-05-06 15:56:33 +0200
committerGravatar Christian Hesse <mail@eworm.de>2014-05-06 15:56:33 +0200
commitd1d726db68059d73a97d03b40eb5366120e6378e (patch)
tree4f32358ec2f27da2a8c1ccd81059a2e5efb162b7
parentf6b270f390f1ff226305888b587dead373884aaa (diff)
downloaddyndhcpd-d1d726db68059d73a97d03b40eb5366120e6378e.tar.gz
dyndhcpd-d1d726db68059d73a97d03b40eb5366120e6378e.tar.zst
use getopt for command line parsing
-rw-r--r--dyndhcpd.c37
1 files 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) {