Use enum number for val of long options (#1155)

This commit is contained in:
anonymous-contributor
2017-02-01 12:53:20 +08:00
committed by Max Lv
parent c0030f0d7d
commit a3d0f02c3e
6 changed files with 155 additions and 142 deletions
+36 -34
View File
@@ -1351,50 +1351,51 @@ main(int argc, char **argv)
char *nameservers[MAX_DNS_NUM + 1];
int nameserver_num = 0;
int option_index = 0;
static struct option long_options[] = {
{ "fast-open", no_argument, 0, 0 },
{ "acl", required_argument, 0, 0 },
{ "manager-address", required_argument, 0, 0 },
{ "mtu", required_argument, 0, 0 },
{ "help", no_argument, 0, 0 },
{ "plugin", required_argument, 0, 0 },
{ "plugin-opts", required_argument, 0, 0 },
{ "fast-open", no_argument, NULL, GETOPT_VAL_FAST_OPEN },
{ "acl", required_argument, NULL, GETOPT_VAL_ACL },
{ "manager-address", required_argument, NULL,
GETOPT_VAL_MANAGER_ADDRESS },
{ "mtu", required_argument, NULL, GETOPT_VAL_MTU },
{ "help", no_argument, NULL, GETOPT_VAL_HELP },
{ "plugin", required_argument, NULL, GETOPT_VAL_PLUGIN },
{ "plugin-opts", required_argument, NULL, GETOPT_VAL_PLUGIN_OPTS },
#ifdef __linux__
{ "mptcp", no_argument, 0, 0 },
{ "mptcp", no_argument, NULL, GETOPT_VAL_MPTCP },
#endif
{ 0, 0, 0, 0 }
{ NULL, 0, NULL, 0 }
};
opterr = 0;
USE_TTY();
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:b:c:i:d:a:n:huUvA6",
long_options, &option_index)) != -1) {
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:b:c:i:d:a:n:huUv6",
long_options, NULL)) != -1) {
switch (c) {
case 0:
if (option_index == 0) {
fast_open = 1;
} else if (option_index == 1) {
LOGI("initializing acl...");
acl = !init_acl(optarg);
} else if (option_index == 2) {
manager_address = optarg;
} else if (option_index == 3) {
mtu = atoi(optarg);
LOGI("set MTU to %d", mtu);
} else if (option_index == 4) {
usage();
exit(EXIT_SUCCESS);
} else if (option_index == 5) {
plugin = optarg;
} else if (option_index == 6) {
plugin_opts = optarg;
} else if (option_index == 7) {
mptcp = 1;
LOGI("enable multipath TCP");
}
case GETOPT_VAL_FAST_OPEN:
fast_open = 1;
break;
case GETOPT_VAL_ACL:
LOGI("initializing acl...");
acl = !init_acl(optarg);
break;
case GETOPT_VAL_MANAGER_ADDRESS:
manager_address = optarg;
break;
case GETOPT_VAL_MTU:
mtu = atoi(optarg);
LOGI("set MTU to %d", mtu);
break;
case GETOPT_VAL_PLUGIN:
plugin = optarg;
break;
case GETOPT_VAL_PLUGIN_OPTS:
plugin_opts = optarg;
break;
case GETOPT_VAL_MPTCP:
mptcp = 1;
LOGI("enable multipath TCP");
break;
case 's':
if (server_num < MAX_REMOTE_NUM) {
@@ -1448,6 +1449,7 @@ main(int argc, char **argv)
case 'v':
verbose = 1;
break;
case GETOPT_VAL_HELP:
case 'h':
usage();
exit(EXIT_SUCCESS);