[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) ;
|
strncpy(options.iface, optarg, IFNAMSIZ + 1) ;
|
||||||
break ;
|
break ;
|
||||||
case 'l' :
|
case 'l' :
|
||||||
/* Facultative getopt options does not handle separated
|
/* Facultative getopt options do not handle separated values
|
||||||
* values (like -l <port>) */
|
* (like -l <port>), so we have to test separately.
|
||||||
if (optarg == 0)
|
*/
|
||||||
|
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
|
/* If we are at the end of the string, or the next optind
|
||||||
* is an option, we have -l without a port number */
|
* is an option, we have -l without a port number */
|
||||||
|
@ -151,8 +154,6 @@ void parse_main_options(int argc, char **argv)
|
||||||
optind++ ;
|
optind++ ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // We got an option like -l<port>, it's OK
|
|
||||||
options.listening_port = strtoul(optarg, NULL, 0) ;
|
|
||||||
break ;
|
break ;
|
||||||
case 'n' :
|
case 'n' :
|
||||||
options.nb_pkt = strtoul(optarg, NULL, 0) ;
|
options.nb_pkt = strtoul(optarg, NULL, 0) ;
|
||||||
|
|
Loading…
Reference in New Issue