From 404ec62b7999755aea2bed232068e927b779775a Mon Sep 17 00:00:00 2001 From: Max Lv Date: Mon, 18 Feb 2019 09:59:40 +0800 Subject: [PATCH] Fix #2285 --- src/jconf.c | 3 +-- src/local.c | 5 ++--- src/redir.c | 3 +-- src/server.c | 26 ++++++++++++++------------ src/tunnel.c | 3 +-- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/jconf.c b/src/jconf.c index 1cbf6e53..5421d18d 100644 --- a/src/jconf.c +++ b/src/jconf.c @@ -211,8 +211,7 @@ read_jconf(const char *file) conf.remote_num = j + 1; } } else if (value->type == json_string) { - conf.remote_addr[0].host = to_string(value); - conf.remote_addr[0].port = NULL; + parse_addr(to_string(value), conf.remote_addr); conf.remote_num = 1; } } else if (strcmp(name, "port_password") == 0) { diff --git a/src/local.c b/src/local.c index 5ca7458b..d882b454 100644 --- a/src/local.c +++ b/src/local.c @@ -1531,8 +1531,7 @@ main(int argc, char **argv) break; case 's': if (remote_num < MAX_REMOTE_NUM) { - remote_addr[remote_num].host = optarg; - remote_addr[remote_num++].port = NULL; + parse_addr(optarg, &remote_addr[remote_num++]); } break; case 'p': @@ -1683,7 +1682,7 @@ main(int argc, char **argv) if (ipv6first == 0) { ipv6first = conf->ipv6_first; } - if (acl == 0) { + if (acl == 0 && conf->acl != NULL) { LOGI("initializing acl..."); acl = !init_acl(conf->acl); } diff --git a/src/redir.c b/src/redir.c index 9ca86edc..41339746 100644 --- a/src/redir.c +++ b/src/redir.c @@ -911,8 +911,7 @@ main(int argc, char **argv) break; case 's': if (remote_num < MAX_REMOTE_NUM) { - remote_addr[remote_num].host = optarg; - remote_addr[remote_num++].port = NULL; + parse_addr(optarg, &remote_addr[remote_num++]); } break; case 'p': diff --git a/src/server.c b/src/server.c index e0bcc51e..5d80739b 100644 --- a/src/server.c +++ b/src/server.c @@ -440,6 +440,7 @@ create_and_bind(const char *host, const char *port, int mptcp) break; } else { ERROR("bind"); + FATAL("failed to bind address"); } close(listen_sock); @@ -1610,7 +1611,7 @@ main(int argc, char **argv) char tmp_port[8]; int server_num = 0; - const char *server_host[MAX_REMOTE_NUM]; + ss_addr_t server_addr[MAX_REMOTE_NUM]; char *nameservers = NULL; @@ -1676,7 +1677,7 @@ main(int argc, char **argv) break; case 's': if (server_num < MAX_REMOTE_NUM) { - server_host[server_num++] = optarg; + parse_addr(optarg, &server_addr[server_num++]); } break; case 'b': @@ -1759,7 +1760,7 @@ main(int argc, char **argv) if (server_num == 0) { server_num = conf->remote_num; for (i = 0; i < server_num; i++) - server_host[i] = conf->remote_addr[i].host; + server_addr[i] = conf->remote_addr[i]; } if (server_port == NULL) { server_port = conf->remote_port; @@ -1817,14 +1818,14 @@ main(int argc, char **argv) if (ipv6first == 0) { ipv6first = conf->ipv6_first; } - if (acl == 0) { + if (acl == 0 && conf->acl != NULL) { LOGI("initializing acl..."); acl = !init_acl(conf->acl); } } if (server_num == 0) { - server_host[server_num++] = "0.0.0.0"; + server_addr[server_num++].host = "0.0.0.0"; } if (server_num == 0 || server_port == NULL @@ -1982,10 +1983,10 @@ main(int argc, char **argv) size_t buf_size = 256 * server_num; char *server_str = ss_malloc(buf_size); - snprintf(server_str, buf_size, "%s", server_host[0]); + snprintf(server_str, buf_size, "%s", server_addr[0].host); len = strlen(server_str); for (int i = 1; i < server_num; i++) { - snprintf(server_str + len, buf_size - len, "|%s", server_host[i]); + snprintf(server_str + len, buf_size - len, "|%s", server_addr[i].host); len = strlen(server_str); } @@ -2008,16 +2009,17 @@ main(int argc, char **argv) if (mode != UDP_ONLY) { int num_listen_ctx = 0; for (int i = 0; i < server_num; i++) { - const char *host = server_host[i]; + const char *host = server_addr[i].host; + const char *port = server_addr[i].port ? server_addr[i].port : server_port; if (plugin != NULL) { host = "127.0.0.1"; } if (host && ss_is_ipv6addr(host)) - LOGI("tcp server listening at [%s]:%s", host, server_port); + LOGI("tcp server listening at [%s]:%s", host, port); else - LOGI("tcp server listening at %s:%s", host ? host : "0.0.0.0", server_port); + LOGI("tcp server listening at %s:%s", host ? host : "0.0.0.0", port); // Bind to port int listenfd; @@ -2056,8 +2058,8 @@ main(int argc, char **argv) if (mode != TCP_ONLY) { int num_listen_ctx = 0; for (int i = 0; i < server_num; i++) { - const char *host = server_host[i]; - const char *port = server_port; + const char *host = server_addr[i].host; + const char *port = server_addr[i].port ? server_addr[i].port : server_port; if (plugin != NULL) { port = plugin_port; } diff --git a/src/tunnel.c b/src/tunnel.c index d9fa11dd..f6c2a90b 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -947,8 +947,7 @@ main(int argc, char **argv) break; case 's': if (remote_num < MAX_REMOTE_NUM) { - remote_addr[remote_num].host = optarg; - remote_addr[remote_num++].port = NULL; + parse_addr(optarg, &remote_addr[remote_num++]); } break; case 'p':