summaryrefslogtreecommitdiff
path: root/src/ipaddrcheck.c
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2013-06-03 13:38:10 -0700
committerDaniil Baturin <daniil@baturin.org>2013-06-03 13:38:10 -0700
commit23692d481ac96d265f00dd3f1acb5ae3dd4ac41b (patch)
tree047bbed3c30456a5473389cef01e4290295a6575 /src/ipaddrcheck.c
parent8902fd3ba0a6b8e2d29543f0b54836e0a6537eec (diff)
downloadipaddrcheck-23692d481ac96d265f00dd3f1acb5ae3dd4ac41b.tar.gz
ipaddrcheck-23692d481ac96d265f00dd3f1acb5ae3dd4ac41b.zip
Improve option/argument errors handling.
Diffstat (limited to 'src/ipaddrcheck.c')
-rw-r--r--src/ipaddrcheck.c24
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 */