diff options
author | Daniil Baturin <daniil@baturin.org> | 2013-06-03 13:38:10 -0700 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2013-06-03 13:38:10 -0700 |
commit | 23692d481ac96d265f00dd3f1acb5ae3dd4ac41b (patch) | |
tree | 047bbed3c30456a5473389cef01e4290295a6575 | |
parent | 8902fd3ba0a6b8e2d29543f0b54836e0a6537eec (diff) | |
download | ipaddrcheck-23692d481ac96d265f00dd3f1acb5ae3dd4ac41b.tar.gz ipaddrcheck-23692d481ac96d265f00dd3f1acb5ae3dd4ac41b.zip |
Improve option/argument errors handling.
-rw-r--r-- | src/ipaddrcheck.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/ipaddrcheck.c b/src/ipaddrcheck.c index 07ed4f4..9c07040 100644 --- a/src/ipaddrcheck.c +++ b/src/ipaddrcheck.c @@ -99,6 +99,9 @@ int main(int argc, char* argv[]) int allow_loopback = NO_LOOPBACK; /* Allow IPv4 loopback in --is-valid-intf-address */ + int no_action = 0; /* Indicates the option modifies program behaviour + but doesn't have its own action */ + const char* program_name = argv[0]; /* Program name for use in messages */ @@ -182,7 +185,7 @@ int main(int argc, char* argv[]) break; case 'C': allow_loopback = LOOPBACK_ALLOWED; - action = NO_ACTION; + no_action = NO_ACTION; break; case 'D': action = IS_ANY_HOST; @@ -203,8 +206,23 @@ int main(int argc, char* argv[]) break; } - action_count = optind-2; - actions[action_count] = action; + if( no_action != NO_ACTION ) + { + action_count = optind-2; + actions[action_count] = action; + } + else + { + no_action = 0; /* Reset no_action */ + } + } + + /* Exit if no option given */ + if( optind < 2 ) + { + fprintf(stderr, "Error: at least one option expected!\n"); + print_help(program_name); + return(RESULT_INT_ERROR); } /* Get non-option arguments */ |