Better optional argument handling.
[tinc] / src / tincd.c
index 333a207..5f1447e 100644 (file)
@@ -167,7 +167,9 @@ static bool parse_options(int argc, char **argv) {
                                break;
 #endif
 
-                       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
@@ -214,6 +216,8 @@ static bool parse_options(int argc, char **argv) {
 
                        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;
@@ -231,6 +235,12 @@ static bool parse_options(int argc, char **argv) {
                }
        }
 
+       if(optind < argc) {
+               fprintf(stderr, "%s: unrecognized argument '%s'\n", argv[0], argv[optind]);
+               usage(true);
+               return false;
+       }
+
        if(!netname && (netname = getenv("NETNAME")))
                netname = xstrdup(netname);