diff options
author | Clemence Faure <clemence.faure@sophos.com> | 2013-07-23 15:00:18 +0200 |
---|---|---|
committer | Florian Westphal <fw@strlen.de> | 2013-07-24 14:59:40 +0200 |
commit | 8e9906b69b03eb12fc75e857a347c4505332b820 (patch) | |
tree | 74af731b78e4a2237e52ba8f8002c4203f778680 | |
parent | 89d016bb2cd72013cec1ae1c5cb2dfff15563d51 (diff) | |
download | conntrack-tools-8e9906b69b03eb12fc75e857a347c4505332b820.tar.gz conntrack-tools-8e9906b69b03eb12fc75e857a347c4505332b820.zip |
conntrack: fix reporting of unknown arguments
short options were always reported as "unknown argument".
getopt(3) says:
if [it] finds an option character in argv that was not included in
optstring, or if it detects a missing option argument, it returns '?'
and sets the external variable optopt to the actual option character.
If the first character [...] of optstring is a colon (':'),
then getopt() returns ':' instead of '?' to indicate a missing option
argument.
Signed-off-by: Clemence Faure <clemence.faure@sophos.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
-rw-r--r-- | src/conntrack.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/conntrack.c b/src/conntrack.c index af36f78..7d2a365 100644 --- a/src/conntrack.c +++ b/src/conntrack.c @@ -333,7 +333,7 @@ static struct option original_opts[] = { {0, 0, 0, 0} }; -static const char *getopt_str = "L::I::U::D::G::E::F::hVs:d:r:q:" +static const char *getopt_str = ":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:C::Sj::w:l:"; @@ -2054,15 +2054,13 @@ int main(int argc, char *argv[]) socketbuffersize = atol(optarg); options |= CT_OPT_BUFFERSIZE; break; + case ':': + exit_error(PARAMETER_PROBLEM, + "option `%s' requires an " + "argument", argv[optind-1]); 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]); + exit_error(PARAMETER_PROBLEM, + "unknown option `%s'", argv[optind-1]); break; default: if (h && h->parse_opts |