[Client] Better optarg test for -l
This commit is contained in:
parent
c63da8bdfc
commit
2597295f08
|
@ -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 <port>) */
|
||||
if (optarg == 0)
|
||||
/* Facultative getopt options do not handle separated values
|
||||
* (like -l <port>), so we have to test separately.
|
||||
*/
|
||||
if (optarg) // We got an option like -l<port>, it's OK
|
||||
options.listening_port = strtoul(optarg, NULL, 0) ;
|
||||
else // We got -l alone or -l <port>
|
||||
{
|
||||
/* 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<port>, it's OK
|
||||
options.listening_port = strtoul(optarg, NULL, 0) ;
|
||||
break ;
|
||||
case 'n' :
|
||||
options.nb_pkt = strtoul(optarg, NULL, 0) ;
|
||||
|
|
Loading…
Reference in New Issue