diff --git a/src/local.c b/src/local.c index 2ac0609c..f3d11e8c 100644 --- a/src/local.c +++ b/src/local.c @@ -1063,7 +1063,7 @@ int main(int argc, char **argv) FATAL("listen() error"); } setnonblocking(listenfd); - LOGI("server listening at port %s", local_port); + LOGI("listening at %s:%s", local_addr, local_port); // Setup proxy context struct listen_ctx listen_ctx; @@ -1196,7 +1196,7 @@ int start_ss_local_server(profile_t profile) return -1; } setnonblocking(listenfd); - LOGI("server listening at port %s", local_port_str); + LOGI("listening at %s:%s", local_addr, local_port_str); // Setup proxy context struct listen_ctx listen_ctx; diff --git a/src/redir.c b/src/redir.c index b051f2db..caa8213b 100644 --- a/src/redir.c +++ b/src/redir.c @@ -719,7 +719,7 @@ int main(int argc, char **argv) FATAL("listen() error"); } setnonblocking(listenfd); - LOGI("server listening at port %s", local_port); + LOGI("listening at %s:%s", local_addr, local_port); // Setup proxy context struct listen_ctx listen_ctx; diff --git a/src/server.c b/src/server.c index dd97fc36..6687fa8d 100644 --- a/src/server.c +++ b/src/server.c @@ -1197,6 +1197,10 @@ int main(int argc, char **argv) resolv_init(loop, nameservers, nameserver_num); } + for (int i = 0; i < nameserver_num; i++) { + LOGI("using nameserver: %s", nameservers[i]); + } + // inilitialize listen context struct listen_ctx listen_ctx_list[server_num]; @@ -1215,11 +1219,7 @@ int main(int argc, char **argv) FATAL("listen() error"); } setnonblocking(listenfd); - LOGI("server listening at port %s", server_port); - - for (int i = 0; i < nameserver_num; i++) { - LOGI("using nameserver: %s", nameservers[i]); - } + LOGI("listening at %s:%s", host, server_port); struct listen_ctx *listen_ctx = &listen_ctx_list[index]; @@ -1232,13 +1232,17 @@ int main(int argc, char **argv) ev_io_init(&listen_ctx->io, accept_cb, listenfd, EV_READ); ev_io_start(loop, &listen_ctx->io); + + // Setup UDP + if (udprelay) { + init_udprelay(server_host[index], server_port, m, atoi(timeout), + iface); + } + } - // Setup UDP if (udprelay) { LOGI("udprelay enabled"); - init_udprelay(server_host[0], server_port, m, atoi(timeout), - iface); } // setuid diff --git a/src/tunnel.c b/src/tunnel.c index da8f0425..b1bd5061 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -784,7 +784,7 @@ int main(int argc, char **argv) FATAL("listen() error:"); } setnonblocking(listenfd); - LOGI("server listening at port %s", local_port); + LOGI("listening at %s:%s", local_addr, local_port); // Setup proxy context struct listen_ctx listen_ctx; diff --git a/src/udprelay.c b/src/udprelay.c index 5f49656c..816b35a7 100644 --- a/src/udprelay.c +++ b/src/udprelay.c @@ -95,7 +95,8 @@ static struct remote_ctx * new_remote(int fd, struct server_ctx * server_ctx); extern int verbose; -static struct server_ctx *server_ctx = NULL; +static int server_num = 0; +static struct server_ctx *server_ctx_list[MAX_REMOTE_NUM] = { NULL }; #ifndef __MINGW32__ static int setnonblocking(int fd) @@ -973,7 +974,7 @@ int init_udprelay(const char *server_host, const char *server_port, } setnonblocking(serverfd); - server_ctx = new_server_ctx(serverfd); + struct server_ctx *server_ctx = new_server_ctx(serverfd); #ifdef UDPRELAY_REMOTE server_ctx->loop = loop; #endif @@ -991,17 +992,20 @@ int init_udprelay(const char *server_host, const char *server_port, ev_io_start(loop, &server_ctx->io); + server_ctx_list[server_num++] = server_ctx; + return 0; } void free_udprelay() { struct ev_loop *loop = EV_DEFAULT; - if (server_ctx != NULL) { + while (server_num-- > 0) { + struct server_ctx *server_ctx = server_ctx_list[server_num]; ev_io_stop(loop, &server_ctx->io); close(server_ctx->fd); cache_delete(server_ctx->conn_cache, 0); free(server_ctx); - server_ctx = NULL; + server_ctx_list[server_num] = NULL; } }