Browse Source

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

* ss-libev: local: Use enum number for val of long options

Signed-off-by: Adam Anonymous <anonymous_temp_mail@yahoo.co.jp>

* ss-libev: manager: Use enum number for val of long options

Signed-off-by: Adam Anonymous <anonymous_temp_mail@yahoo.co.jp>

* ss-libev: redir: Use enum number for val of long options

Signed-off-by: Adam Anonymous <anonymous_temp_mail@yahoo.co.jp>

* ss-libev: server: Use enum number for val of long options

Signed-off-by: Adam Anonymous <anonymous_temp_mail@yahoo.co.jp>

* ss-libev: tunnel: Use enum number for val of long options

Signed-off-by: Adam Anonymous <anonymous_temp_mail@yahoo.co.jp>
pull/1156/head
anonymous-contributor 8 years ago
committed by Max Lv
parent
commit
1fc17aca38
6 changed files with 153 additions and 139 deletions
  1. 62
      src/local.c
  2. 63
      src/manager.c
  3. 41
      src/redir.c
  4. 68
      src/server.c
  5. 46
      src/tunnel.c
  6. 12
      src/utils.h

62
src/local.c

@ -1189,16 +1189,15 @@ main(int argc, char **argv)
ss_addr_t remote_addr[MAX_REMOTE_NUM];
char *remote_port = NULL;
int option_index = 0;
static struct option long_options[] = {
{ "fast-open", no_argument, 0, 0 },
{ "acl", required_argument, 0, 0 },
{ "mtu", required_argument, 0, 0 },
{ "mptcp", no_argument, 0, 0 },
{ "plugin", required_argument, 0, 0 },
{ "plugin-opts", required_argument, 0, 0 },
{ "help", no_argument, 0, 0 },
{ 0, 0, 0, 0 }
{ "fast-open", no_argument, NULL, GETOPT_VAL_FAST_OPEN },
{ "acl", required_argument, NULL, GETOPT_VAL_ACL },
{ "mtu", required_argument, NULL, GETOPT_VAL_MTU },
{ "mptcp", no_argument, NULL, GETOPT_VAL_MPTCP },
{ "plugin", required_argument, NULL, GETOPT_VAL_PLUGIN },
{ "plugin-opts", required_argument, NULL, GETOPT_VAL_PLUGIN_OPTS },
{ "help", no_argument, NULL, GETOPT_VAL_HELP },
{ NULL, 0, NULL, 0 }
};
opterr = 0;
@ -1207,32 +1206,32 @@ main(int argc, char **argv)
#ifdef ANDROID
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:n:huUvVA6",
long_options, &option_index)) != -1) {
long_options, NULL)) != -1) {
#else
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:a:n:huUvA6",
long_options, &option_index)) != -1) {
long_options, NULL)) != -1) {
#endif
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) {
mtu = atoi(optarg);
LOGI("set MTU to %d", mtu);
} else if (option_index == 3) {
mptcp = 1;
LOGI("enable multipath TCP");
} else if (option_index == 4) {
plugin = optarg;
} else if (option_index == 5) {
plugin_opts = optarg;
} else if (option_index == 6) {
usage();
exit(EXIT_SUCCESS);
}
case GETOPT_VAL_FAST_OPEN:
fast_open = 1;
break;
case GETOPT_VAL_ACL:
LOGI("initializing acl...");
acl = !init_acl(optarg);
break;
case GETOPT_VAL_MTU:
mtu = atoi(optarg);
LOGI("set MTU to %d", mtu);
break;
case GETOPT_VAL_MPTCP:
mptcp = 1;
LOGI("enable multipath TCP");
break;
case GETOPT_VAL_PLUGIN:
plugin = optarg;
break;
case GETOPT_VAL_PLUGIN_OPTS:
plugin_opts = optarg;
break;
case 's':
if (remote_num < MAX_REMOTE_NUM) {
@ -1286,6 +1285,7 @@ main(int argc, char **argv)
verbose = 1;
break;
case 'h':
case GETOPT_VAL_HELP:
usage();
exit(EXIT_SUCCESS);
case 'A':

63
src/manager.c

@ -894,17 +894,18 @@ main(int argc, char **argv)
jconf_t *conf = NULL;
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 },
{ "executable", required_argument, 0, 0 },
{ "mtu", required_argument, 0, 0 },
{ "plugin", required_argument, 0, 0 },
{ "plugin-opts", required_argument, 0, 0 },
{ "help", no_argument, 0, 0 },
{ 0, 0, 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 },
{ "executable", required_argument, NULL,
GETOPT_VAL_EXECUTABLE },
{ "mtu", required_argument, NULL, GETOPT_VAL_MTU },
{ "plugin", required_argument, NULL, GETOPT_VAL_PLUGIN },
{ "plugin-opts", required_argument, NULL, GETOPT_VAL_PLUGIN_OPTS },
{ "help", no_argument, NULL, GETOPT_VAL_HELP },
{ NULL, 0, NULL, 0 }
};
opterr = 0;
@ -912,27 +913,28 @@ main(int argc, char **argv)
USE_TTY();
while ((c = getopt_long(argc, argv, "f:s:l:k:t:m:c:i:d:a:n:6huUvA",
long_options, &option_index)) != -1)
long_options, NULL)) != -1)
switch (c) {
case 0:
if (option_index == 0) {
fast_open = 1;
} else if (option_index == 1) {
acl = optarg;
} else if (option_index == 2) {
manager_address = optarg;
} else if (option_index == 3) {
executable = optarg;
} else if (option_index == 4) {
mtu = atoi(optarg);
} else if (option_index == 5) {
plugin = optarg;
} else if (option_index == 6) {
plugin_opts = optarg;
} else if (option_index == 7) {
usage();
exit(EXIT_SUCCESS);
}
case GETOPT_VAL_FAST_OPEN:
fast_open = 1;
break;
case GETOPT_VAL_ACL:
acl = optarg;
break;
case GETOPT_VAL_MANAGER_ADDRESS:
manager_address = optarg;
break;
case GETOPT_VAL_EXECUTABLE:
executable = optarg;
break;
case GETOPT_VAL_MTU:
mtu = atoi(optarg);
break;
case GETOPT_VAL_PLUGIN:
plugin = optarg;
break;
case GETOPT_VAL_PLUGIN_OPTS:
plugin_opts = optarg;
break;
case 's':
if (server_num < MAX_REMOTE_NUM) {
@ -978,6 +980,7 @@ main(int argc, char **argv)
case 'v':
verbose = 1;
break;
case GETOPT_VAL_HELP:
case 'h':
usage();
exit(EXIT_SUCCESS);

41
src/redir.c

@ -805,12 +805,12 @@ main(int argc, char **argv)
int option_index = 0;
static struct option long_options[] = {
{ "mtu", required_argument, 0, 0 },
{ "mptcp", no_argument, 0, 0 },
{ "plugin", required_argument, 0, 0 },
{ "plugin-opts", required_argument, 0, 0 },
{ "help", no_argument, 0, 0 },
{ 0, 0, 0, 0 }
{ "mtu", required_argument, NULL, GETOPT_VAL_MTU },
{ "mptcp", no_argument, NULL, GETOPT_VAL_MPTCP },
{ "plugin", required_argument, NULL, GETOPT_VAL_PLUGIN },
{ "plugin-opts", required_argument, NULL, GETOPT_VAL_PLUGIN_OPTS },
{ "help", no_argument, NULL, GETOPT_VAL_HELP },
{ NULL, 0, NULL, 0 }
};
opterr = 0;
@ -820,21 +820,19 @@ main(int argc, char **argv)
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:c:b:a:n:huUvA6",
long_options, &option_index)) != -1) {
switch (c) {
case 0:
if (option_index == 0) {
mtu = atoi(optarg);
LOGI("set MTU to %d", mtu);
} else if (option_index == 1) {
mptcp = 1;
LOGI("enable multipath TCP");
} else if (option_index == 2) {
plugin = optarg;
} else if (option_index == 3) {
plugin_opts = optarg;
} else if (option_index == 4) {
usage();
exit(EXIT_SUCCESS);
}
case GETOPT_VAL_MTU:
mtu = atoi(optarg);
LOGI("set MTU to %d", mtu);
break;
case GETOPT_VAL_MPTCP:
mptcp = 1;
LOGI("enable multipath TCP");
break;
case GETOPT_VAL_PLUGIN:
plugin = optarg;
break;
case GETOPT_VAL_PLUGIN_OPTS:
plugin_opts = optarg;
break;
case 's':
if (remote_num < MAX_REMOTE_NUM) {
@ -884,6 +882,7 @@ main(int argc, char **argv)
case 'v':
verbose = 1;
break;
case GETOPT_VAL_HELP:
case 'h':
usage();
exit(EXIT_SUCCESS);

68
src/server.c

@ -1582,19 +1582,19 @@ 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;
@ -1602,30 +1602,31 @@ main(int argc, char **argv)
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) {
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) {
@ -1679,6 +1680,7 @@ main(int argc, char **argv)
case 'v':
verbose = 1;
break;
case GETOPT_VAL_HELP:
case 'h':
usage();
exit(EXIT_SUCCESS);

46
src/tunnel.c

@ -758,14 +758,13 @@ main(int argc, char **argv)
ss_addr_t tunnel_addr = { .host = NULL, .port = NULL };
char *tunnel_addr_str = NULL;
int option_index = 0;
static struct option long_options[] = {
{ "mtu", required_argument, 0, 0 },
{ "mptcp", no_argument, 0, 0 },
{ "plugin", required_argument, 0, 0 },
{ "plugin-opts", required_argument, 0, 0 },
{ "help", no_argument, 0, 0 },
{ 0, 0, 0, 0 }
{ "mtu", required_argument, NULL, GETOPT_VAL_MTU },
{ "mptcp", no_argument, NULL, GETOPT_VAL_MPTCP },
{ "plugin", required_argument, NULL, GETOPT_VAL_PLUGIN },
{ "plugin-opts", required_argument, NULL, GETOPT_VAL_PLUGIN_OPTS },
{ "help", no_argument, NULL, GETOPT_VAL_HELP },
{ NULL, 0, NULL, 0}
};
opterr = 0;
@ -774,27 +773,25 @@ main(int argc, char **argv)
#ifdef ANDROID
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:n:huUvVA6",
long_options, &option_index)) != -1) {
long_options, NULL)) != -1) {
#else
while ((c = getopt_long(argc, argv, "f:s:p:l:k:t:m:i:c:b:L:a:n:huUvA6",
long_options, &option_index)) != -1) {
long_options, NULL)) != -1) {
#endif
switch (c) {
case 0:
if (option_index == 0) {
mtu = atoi(optarg);
LOGI("set MTU to %d", mtu);
} else if (option_index == 1) {
mptcp = 1;
LOGI("enable multipath TCP");
} else if (option_index == 2) {
plugin = optarg;
} else if (option_index == 3) {
plugin_opts = optarg;
} else if (option_index == 4) {
usage();
exit(EXIT_SUCCESS);
}
case GETOPT_VAL_MTU:
mtu = atoi(optarg);
LOGI("set MTU to %d", mtu);
break;
case GETOPT_VAL_MPTCP:
mptcp = 1;
LOGI("enable multipath TCP");
break;
case GETOPT_VAL_PLUGIN:
plugin = optarg;
break;
case GETOPT_VAL_PLUGIN_OPTS:
plugin_opts = optarg;
break;
case 's':
if (remote_num < MAX_REMOTE_NUM) {
@ -850,6 +847,7 @@ main(int argc, char **argv)
case 'v':
verbose = 1;
break;
case GETOPT_VAL_HELP:
case 'h':
usage();
exit(EXIT_SUCCESS);

12
src/utils.h

@ -161,6 +161,18 @@ extern int use_syslog;
#endif // if ANDROID
/* Vals for long options */
enum { GETOPT_VAL_HELP = 257,
GETOPT_VAL_FAST_OPEN,
GETOPT_VAL_ACL,
GETOPT_VAL_MTU,
GETOPT_VAL_MPTCP,
GETOPT_VAL_PLUGIN,
GETOPT_VAL_PLUGIN_OPTS,
GETOPT_VAL_MANAGER_ADDRESS,
GETOPT_VAL_EXECUTABLE
};
void ERROR(const char *s);
char *ss_itoa(int i);

Loading…
Cancel
Save