From 2597295f083b0965626adecbf7d936447751a921 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Fri, 1 Jul 2011 14:21:31 +0200 Subject: [PATCH] [Client] Better optarg test for -l --- owlps-client/owlps-client.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/owlps-client/owlps-client.c b/owlps-client/owlps-client.c index f9d7c2e..1a0aef1 100644 --- a/owlps-client/owlps-client.c +++ b/owlps-client/owlps-client.c @@ -134,9 +134,12 @@ void parse_main_options(int argc, char **argv) strncpy(options.iface, optarg, IFNAMSIZ + 1) ; break ; case 'l' : - /* Facultative getopt options does not handle separated - * values (like -l ) */ - if (optarg == 0) + /* Facultative getopt options do not handle separated values + * (like -l ), so we have to test separately. + */ + if (optarg) // We got an option like -l, it's OK + options.listening_port = strtoul(optarg, NULL, 0) ; + else // We got -l alone or -l { /* If we are at the end of the string, or the next optind * is an option, we have -l without a port number */ @@ -151,8 +154,6 @@ void parse_main_options(int argc, char **argv) optind++ ; } } - else // We got an option like -l, it's OK - options.listening_port = strtoul(optarg, NULL, 0) ; break ; case 'n' : options.nb_pkt = strtoul(optarg, NULL, 0) ;