Some options can take an optional argument. However, in this case GNU getopt
requires that the optional argument is right next to the option without
whitespace inbetween. If there is whitespace, getopt will treat it as a
non-option argument, but tinc ignored those without a warning. Now tinc will
allow optional arguments with whitespace inbetween, and will give an error when
it encounters any other non-option arguments.
- case 'd': /* inc debug level */
+ case 'd': /* increase debug level */
+ if(!optarg && optind < argc && *argv[optind] != '-')
+ optarg = argv[optind++];
if(optarg)
debug_level = atoi(optarg);
else
if(optarg)
debug_level = atoi(optarg);
else
case 'k': /* kill old tincds */
#ifndef HAVE_MINGW
case 'k': /* kill old tincds */
#ifndef HAVE_MINGW
+ if(!optarg && optind < argc && *argv[optind] != '-')
+ optarg = argv[optind++];
if(optarg) {
if(!strcasecmp(optarg, "HUP"))
kill_tincd = SIGHUP;
if(optarg) {
if(!strcasecmp(optarg, "HUP"))
kill_tincd = SIGHUP;
case 'n': /* net name given */
/* netname "." is special: a "top-level name" */
case 'n': /* net name given */
/* netname "." is special: a "top-level name" */
- netname = strcmp(optarg, ".") != 0 ?
- xstrdup(optarg) : NULL;
+ netname = strcmp(optarg, ".") != 0 ? xstrdup(optarg) : NULL;
break;
case 'o': /* option */
break;
case 'o': /* option */
break;
case 'K': /* generate public/private keypair */
break;
case 'K': /* generate public/private keypair */
+ if(!optarg && optind < argc && *argv[optind] != '-')
+ optarg = argv[optind++];
if(optarg) {
generate_keys = atoi(optarg);
if(optarg) {
generate_keys = atoi(optarg);
case 4: /* write log entries to a file */
use_logfile = true;
case 4: /* write log entries to a file */
use_logfile = true;
+ if(!optarg && optind < argc && *argv[optind] != '-')
+ optarg = argv[optind++];
if(optarg)
logfilename = xstrdup(optarg);
break;
if(optarg)
logfilename = xstrdup(optarg);
break;
+ if(optind < argc) {
+ fprintf(stderr, "%s: unrecognized argument '%s'\n", argv[0], argv[optind]);
+ usage(true);
+ return false;
+ }
+