Merge #57 by @zabbius to dev

minor - removed duplicated code in args.c
This commit is contained in:
Vadim Vetrov 2024-08-12 15:24:57 +03:00
commit aafa1a728a
No known key found for this signature in database
GPG Key ID: E8A308689D7A73A5

49
args.c
View File

@ -136,10 +136,10 @@ int parse_args(int argc, char *argv[]) {
switch (opt) {
case 'h':
print_usage(argv[0]);
goto out;
goto stop_exec;
case 'v':
print_version();
goto out;
goto stop_exec;
case OPT_SILENT:
config.verbose = 0;
break;
@ -153,7 +153,6 @@ int parse_args(int argc, char *argv[]) {
config.domains_str = optarg;
config.domains_strlen = strlen(config.domains_str);
break;
case OPT_FRAG:
if (strcmp(optarg, "tcp") == 0) {
@ -163,8 +162,7 @@ int parse_args(int argc, char *argv[]) {
} else if (strcmp(optarg, "none") == 0) {
config.fragmentation_strategy = FRAG_STRAT_NONE;
} else {
printf("Invalid option %s\n", long_opt[optIdx].name);
goto error;
goto invalid_opt;
}
break;
@ -174,9 +172,7 @@ int parse_args(int argc, char *argv[]) {
} else if (strcmp(optarg, "0") == 0) {
config.frag_sni_faked = 0;
} else {
errno = EINVAL;
printf("Invalid option %s\n", long_opt[optIdx].name);
goto error;
goto invalid_opt;
}
break;
@ -186,9 +182,7 @@ int parse_args(int argc, char *argv[]) {
} else if (strcmp(optarg, "0") == 0) {
config.frag_sni_reverse = 0;
} else {
errno = EINVAL;
printf("Invalid option %s\n", long_opt[optIdx].name);
goto error;
goto invalid_opt;
}
break;
@ -198,17 +192,14 @@ int parse_args(int argc, char *argv[]) {
} else if (strcmp(optarg, "ttl") == 0) {
config.faking_strategy = FAKE_STRAT_TTL;
} else {
errno = EINVAL;
printf("Invalid option %s\n", long_opt[optIdx].name);
goto error;
goto invalid_opt;
}
break;
case OPT_FAKING_TTL:
num = parse_numeric_option(optarg);
if (errno != 0 || num < 0 || num > 255) {
printf("Invalid option %s\n", long_opt[optIdx].name);
goto error;
goto invalid_opt;
}
config.faking_ttl = num;
@ -220,17 +211,14 @@ int parse_args(int argc, char *argv[]) {
} else if (strcmp(optarg, "0") == 0) {
config.fake_sni = 0;
} else {
errno = EINVAL;
printf("Invalid option %s\n", long_opt[optIdx].name);
goto error;
goto invalid_opt;
}
break;
case OPT_FAKE_SNI_SEQ_LEN:
num = parse_numeric_option(optarg);
if (errno != 0 || num < 0 || num > 255) {
printf("Invalid option %s\n", long_opt[optIdx].name);
goto error;
goto invalid_opt;
}
config.fake_sni_seq_len = num;
@ -238,8 +226,7 @@ int parse_args(int argc, char *argv[]) {
case OPT_FK_WINSIZE:
num = parse_numeric_option(optarg);
if (errno != 0 || num < 0) {
printf("Invalid option %s\n", long_opt[optIdx].name);
goto error;
goto invalid_opt;
}
config.fk_winsize = num;
@ -247,8 +234,7 @@ int parse_args(int argc, char *argv[]) {
case OPT_SEG2DELAY:
num = parse_numeric_option(optarg);
if (errno != 0 || num < 0) {
printf("Invalid option %s\n", long_opt[optIdx].name);
goto error;
goto invalid_opt;
}
config.seg2_delay = num;
@ -256,8 +242,7 @@ int parse_args(int argc, char *argv[]) {
case OPT_THREADS:
num = parse_numeric_option(optarg);
if (errno != 0 || num < 0 || num > MAX_THREADS) {
printf("Invalid option %s\n", long_opt[optIdx].name);
goto error;
goto invalid_opt;
}
config.threads = num;
@ -265,8 +250,7 @@ int parse_args(int argc, char *argv[]) {
case OPT_QUEUE_NUM:
num = parse_numeric_option(optarg);
if (errno != 0 || num < 0) {
printf("Invalid option %s\n", long_opt[optIdx].name);
goto error;
goto invalid_opt;
}
config.queue_start_num = num;
@ -277,12 +261,15 @@ int parse_args(int argc, char *argv[]) {
}
// out:
errno = 0;
return 0;
out:
stop_exec:
errno = 0;
return 1;
invalid_opt:
printf("Invalid option %s\n", long_opt[optIdx].name);
error:
print_usage(argv[0]);
errno = EINVAL;