Commit 2d0594e5 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Improve command-line error checking.

parent 8396be0f
...@@ -143,7 +143,9 @@ main(int argc, char **argv) ...@@ -143,7 +143,9 @@ main(int argc, char **argv)
} }
break; break;
case 'p': case 'p':
protocol_port = atoi(optarg); protocol_port = parse_nat(optarg);
if(protocol_port <= 0 || protocol_port > 0xFFFF)
goto usage;
break; break;
case 'h': case 'h':
default_wireless_hello_interval = parse_msec(optarg); default_wireless_hello_interval = parse_msec(optarg);
...@@ -158,12 +160,12 @@ main(int argc, char **argv) ...@@ -158,12 +160,12 @@ main(int argc, char **argv)
goto usage; goto usage;
break; break;
case 'k': case 'k':
kernel_metric = atoi(optarg); kernel_metric = parse_nat(optarg);
if(kernel_metric < 0 || kernel_metric > 0xFFFF) if(kernel_metric < 0 || kernel_metric > 0xFFFF)
goto usage; goto usage;
break; break;
case 'A': case 'A':
allow_duplicates = atoi(optarg); allow_duplicates = parse_nat(optarg);
if(allow_duplicates < 0 || allow_duplicates > 0xFFFF) if(allow_duplicates < 0 || allow_duplicates > 0xFFFF)
goto usage; goto usage;
break; break;
...@@ -177,13 +179,17 @@ main(int argc, char **argv) ...@@ -177,13 +179,17 @@ main(int argc, char **argv)
state_file = optarg; state_file = optarg;
break; break;
case 'd': case 'd':
debug = atoi(optarg); debug = parse_nat(optarg);
if(debug < 0)
goto usage;
break; break;
case 'g': case 'g':
#ifdef NO_LOCAL_INTERFACE #ifdef NO_LOCAL_INTERFACE
fprintf(stderr, "Warning: no local interface in this version.\n"); fprintf(stderr, "Warning: no local interface in this version.\n");
#else #else
local_server_port = atoi(optarg); local_server_port = parse_nat(optarg);
if(local_server_port <= 0 || local_server_port > 0xFFFF)
goto usage;
#endif #endif
break; break;
case 'l': case 'l':
...@@ -194,23 +200,25 @@ main(int argc, char **argv) ...@@ -194,23 +200,25 @@ main(int argc, char **argv)
break; break;
case 'z': case 'z':
{ {
char *comma = strchr(optarg, ','); char *comma;
diversity_kind = atoi(optarg); diversity_kind = (int)strtol(optarg, &comma, 0);
if(comma == NULL) if(*comma == '\0')
diversity_factor = 128; diversity_factor = 128;
else if(*comma == ',')
diversity_factor = parse_nat(comma + 1);
else else
diversity_factor = atoi(comma + 1); goto usage;
if(diversity_factor <= 0 || diversity_factor > 256) if(diversity_factor <= 0 || diversity_factor > 256)
goto usage; goto usage;
} }
break; break;
case 't': case 't':
export_table = atoi(optarg); export_table = parse_nat(optarg);
if(export_table < 0 || export_table > 0xFFFF) if(export_table < 0 || export_table > 0xFFFF)
goto usage; goto usage;
break; break;
case 'T': case 'T':
import_table = atoi(optarg); import_table = parse_nat(optarg);
if(import_table < 0 || import_table > 0xFFFF) if(import_table < 0 || import_table > 0xFFFF)
goto usage; goto usage;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment