Browse Source

Refine json config handling. #2308

pull/2310/head
Max Lv 6 years ago
parent
commit
14dd82045e
5 changed files with 26 additions and 14 deletions
  1. 11
      src/jconf.c
  2. 5
      src/local.c
  3. 10
      src/redir.c
  4. 4
      src/server.c
  5. 10
      src/tunnel.c

11
src/jconf.c

@ -68,9 +68,10 @@ parse_addr(const char *str_in, ss_addr_t *addr)
if (str_in == NULL) if (str_in == NULL)
return; return;
int ipv6 = 0, ret = -1, n = 0;
int ipv6 = 0, ret = -1, n = 0, len;
char *pch; char *pch;
char *str = strdup(str_in); char *str = strdup(str_in);
len = strlen(str_in);
struct cork_ip ip; struct cork_ip ip;
if (cork_ip_init(&ip, str) != -1) { if (cork_ip_init(&ip, str) != -1) {
@ -85,6 +86,7 @@ parse_addr(const char *str_in, ss_addr_t *addr)
ret = pch - str; ret = pch - str;
pch = strchr(pch + 1, ':'); pch = strchr(pch + 1, ':');
} }
if (n > 1) { if (n > 1) {
ipv6 = 1; ipv6 = 1;
if (str[ret - 1] != ']') { if (str[ret - 1] != ']') {
@ -105,7 +107,12 @@ parse_addr(const char *str_in, ss_addr_t *addr)
} else { } else {
addr->host = ss_strndup(str, ret); addr->host = ss_strndup(str, ret);
} }
addr->port = strdup(str + ret + 1);
if (ret < len - 1)
{
addr->port = strdup(str + ret + 1);
} else {
addr->port = NULL;
}
} }
free(str); free(str);

5
src/local.c

@ -1465,12 +1465,13 @@ main(int argc, char **argv)
char *plugin_port = NULL; char *plugin_port = NULL;
char tmp_port[8]; char tmp_port[8];
srand(time(NULL));
int remote_num = 0; int remote_num = 0;
ss_addr_t remote_addr[MAX_REMOTE_NUM]; ss_addr_t remote_addr[MAX_REMOTE_NUM];
char *remote_port = NULL; char *remote_port = NULL;
memset(remote_addr, 0, sizeof(ss_addr_t) * MAX_REMOTE_NUM);
srand(time(NULL));
static struct option long_options[] = { static struct option long_options[] = {
{ "reuse-port", no_argument, NULL, GETOPT_VAL_REUSE_PORT }, { "reuse-port", no_argument, NULL, GETOPT_VAL_REUSE_PORT },
{ "fast-open", no_argument, NULL, GETOPT_VAL_FAST_OPEN }, { "fast-open", no_argument, NULL, GETOPT_VAL_FAST_OPEN },

10
src/redir.c

@ -854,13 +854,15 @@ main(int argc, char **argv)
char *plugin_port = NULL; char *plugin_port = NULL;
char tmp_port[8]; char tmp_port[8];
int remote_num = 0;
ss_addr_t remote_addr[MAX_REMOTE_NUM];
char *remote_port = NULL;
int dscp_num = 0; int dscp_num = 0;
ss_dscp_t *dscp = NULL; ss_dscp_t *dscp = NULL;
int remote_num = 0;
char *remote_port = NULL;
ss_addr_t remote_addr[MAX_REMOTE_NUM];
memset(remote_addr, 0, sizeof(ss_addr_t) * MAX_REMOTE_NUM);
static struct option long_options[] = { static struct option long_options[] = {
{ "fast-open", no_argument, NULL, GETOPT_VAL_FAST_OPEN }, { "fast-open", no_argument, NULL, GETOPT_VAL_FAST_OPEN },
{ "mtu", required_argument, NULL, GETOPT_VAL_MTU }, { "mtu", required_argument, NULL, GETOPT_VAL_MTU },

4
src/server.c

@ -1610,11 +1610,11 @@ main(int argc, char **argv)
char *plugin_host = NULL; char *plugin_host = NULL;
char *plugin_port = NULL; char *plugin_port = NULL;
char tmp_port[8]; char tmp_port[8];
char *nameservers = NULL;
int server_num = 0; int server_num = 0;
ss_addr_t server_addr[MAX_REMOTE_NUM]; ss_addr_t server_addr[MAX_REMOTE_NUM];
char *nameservers = NULL;
memset(server_addr, 0, sizeof(ss_addr_t) * MAX_REMOTE_NUM);
static struct option long_options[] = { static struct option long_options[] = {
{ "fast-open", no_argument, NULL, GETOPT_VAL_FAST_OPEN }, { "fast-open", no_argument, NULL, GETOPT_VAL_FAST_OPEN },

10
src/tunnel.c

@ -885,13 +885,15 @@ main(int argc, char **argv)
char *plugin_port = NULL; char *plugin_port = NULL;
char tmp_port[8]; char tmp_port[8];
int remote_num = 0;
ss_addr_t remote_addr[MAX_REMOTE_NUM];
char *remote_port = NULL;
ss_addr_t tunnel_addr = { .host = NULL, .port = NULL }; ss_addr_t tunnel_addr = { .host = NULL, .port = NULL };
char *tunnel_addr_str = NULL; char *tunnel_addr_str = NULL;
int remote_num = 0;
char *remote_port = NULL;
ss_addr_t remote_addr[MAX_REMOTE_NUM];
memset(remote_addr, 0, sizeof(ss_addr_t) * MAX_REMOTE_NUM);
static struct option long_options[] = { static struct option long_options[] = {
{ "fast-open", no_argument, NULL, GETOPT_VAL_FAST_OPEN }, { "fast-open", no_argument, NULL, GETOPT_VAL_FAST_OPEN },
{ "mtu", required_argument, NULL, GETOPT_VAL_MTU }, { "mtu", required_argument, NULL, GETOPT_VAL_MTU },

Loading…
Cancel
Save