diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2008-08-12 18:08:07 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2008-08-12 18:08:07 +0200 |
commit | b18a146363f170afa420af04f80d2a91c38f11a3 (patch) | |
tree | a007bc8278006c22baf49155be2596baec698dd2 | |
parent | e50e3a5b0f426571d6feb16800b991779aab6d8e (diff) |
cli: check for missing arguments in getopt_long
From: Pablo Neira Ayuso <pablo@netfilter.org>
If getopt_long returns '?', show an error telling that some
arguments are missing.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | src/conntrack.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/conntrack.c b/src/conntrack.c index ab3da8a..c126557 100644 --- a/src/conntrack.c +++ b/src/conntrack.c @@ -934,6 +934,9 @@ int main(int argc, char *argv[]) register_icmp(); register_icmpv6(); + /* disable explicit missing arguments error output from getopt_long */ + opterr = 0; + while ((c = getopt_long(argc, argv, "L::I::U::D::G::E::F::hVs:d:r:q:" "p:t:u:e:a:z[:]:{:}:m:i:f:o:n::" "g::c:b:", @@ -1076,18 +1079,21 @@ int main(int argc, char *argv[]) socketbuffersize = atol(optarg); options |= CT_OPT_BUFFERSIZE; break; + case '?': + if (optopt) + exit_error(PARAMETER_PROBLEM, + "option `%s' requires an " + "argument", argv[optind-1]); + else + exit_error(PARAMETER_PROBLEM, + "unknown option `%s'", + argv[optind-1]); + break; default: if (h && h->parse_opts &&!h->parse_opts(c - h->option_offset, obj, exptuple, mask, &l4flags)) exit_error(PARAMETER_PROBLEM, "parse error"); - - /* Unknown argument... */ - if (!h) { - usage(argv[0]); - exit_error(PARAMETER_PROBLEM, - "Missing arguments..."); - } break; } } |