Fix coding style of args parser

This commit is contained in:
Vadim Vetrov 2024-08-09 15:58:52 +03:00
parent 4963258c0b
commit 8d4fb1f7ad
No known key found for this signature in database
GPG Key ID: E8A308689D7A73A5

View File

@ -80,7 +80,9 @@ static void print_version() {
}
static void print_usage(const char *argv0) {
printf("Usage: %s [ OPTIONS ] <queue_num> \n", argv0);
print_version();
printf("Usage: %s <queue_num> [ OPTIONS ] \n", argv0);
printf("Options:\n");
printf("\t--sni-domains=<comma separated domain list>|all\n");
printf("\t--fake-sni={ack,ttl,none}\n");
@ -90,6 +92,7 @@ static void print_usage(const char *argv0) {
printf("\t--threads=<threads number>\n");
printf("\t--silent\n");
printf("\t--no-gso\n");
printf("\n");
}
#define OPT_SNI_DOMAINS 1
@ -113,7 +116,7 @@ static struct option long_opt[] = {
{"silent", 0, 0, OPT_SILENT},
{"no-gso", 0, 0, OPT_NO_GSO},
{0,0,0,0}
};
};
static int parse_args(int argc, char *argv[]) {
int opt;
@ -130,12 +133,10 @@ static int parse_args(int argc, char *argv[]) {
switch (opt) {
case 'h':
print_usage(argv[0]);
errno = 0;
return 1;
goto out;
case 'v':
print_version();
errno = 0;
return 1;
goto out;
case OPT_SILENT:
config.verbose = 0;
break;
@ -143,12 +144,12 @@ static int parse_args(int argc, char *argv[]) {
config.use_gso = 0;
break;
case OPT_SNI_DOMAINS:
if (strcmp(optarg, "all")) {
config.all_domains = 1;
}
config.domains_str = optarg;
config.domains_strlen = strlen(config.domains_str);
printf("asdffdsa\n");
break;
case OPT_FRAG:
@ -159,10 +160,10 @@ static int parse_args(int argc, char *argv[]) {
} else if (strcmp(optarg, "none") == 0) {
config.fragmentation_strategy = FRAG_STRAT_NONE;
} else {
errno = EINVAL;
printf("Invalid option %s\n", long_opt[optIdx].name);
return -1;
goto error;
}
break;
case OPT_FAKE_SNI:
if (strcmp(optarg, "ack") == 0) {
@ -174,47 +175,58 @@ static int parse_args(int argc, char *argv[]) {
} else {
errno = EINVAL;
printf("Invalid option %s\n", long_opt[optIdx].name);
return -1;
goto error;
}
break;
case OPT_SEG2DELAY:
num = parse_numeric_option(optarg);
if (errno != 0 || num < 0) {
printf("Invalid option %s\n", long_opt[optIdx].name);
return -1;
goto error;
}
config.seg2_delay = num;
break;
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);
return -1;
goto error;
}
config.threads = num;
break;
case OPT_FAKE_SNI_TTL:
num = parse_numeric_option(optarg);
if (errno != 0 || num < 0 || num > 255) {
printf("Invalid option %s\n", long_opt[optIdx].name);
return -1;
goto error;
}
config.fake_sni_ttl = num;
break;
default:
printf("Invalid option %s\n", long_opt[optIdx].name);
errno = EINVAL;
return -1;
goto error;
}
}
config.queue_start_num = parse_numeric_option(argv[optind]);
if (errno != 0) {
printf("Invalid queue number\n");
return -1;
goto error;
}
errno = 0;
return 0;
out:
errno = 0;
return 1;
error:
print_usage(argv[0]);
errno = EINVAL;
return -1;
}
static int open_socket(struct mnl_socket **_nl) {