Browse Source

Refine interface

pull/1428/head
Max Lv 7 years ago
parent
commit
5b2fb72b14
1 changed files with 9 additions and 13 deletions
  1. 22
      src/local.c

22
src/local.c

@ -1723,20 +1723,20 @@ start_ss_local_server(profile_t profile)
if (crypto == NULL) if (crypto == NULL)
FATAL("failed to init ciphers"); FATAL("failed to init ciphers");
struct sockaddr_storage *storage = ss_malloc(sizeof(struct sockaddr_storage));
memset(storage, 0, sizeof(struct sockaddr_storage));
if (get_sockaddr(remote_host, remote_port_str, storage, 0, ipv6first) == -1) {
struct sockaddr_storage storage;
memset(&storage, 0, sizeof(struct sockaddr_storage));
if (get_sockaddr(remote_host, remote_port_str, &storage, 0, ipv6first) == -1) {
return -1; return -1;
} }
// Setup proxy context // Setup proxy context
struct ev_loop *loop = EV_DEFAULT; struct ev_loop *loop = EV_DEFAULT;
struct sockaddr **remote_addr_tmp = ss_malloc(sizeof(struct sockaddr *));
struct sockaddr *remote_addr_tmp[MAX_REMOTE_NUM];
listen_ctx_t listen_ctx; listen_ctx_t listen_ctx;
listen_ctx.remote_num = 1; listen_ctx.remote_num = 1;
listen_ctx.remote_addr = remote_addr_tmp; listen_ctx.remote_addr = remote_addr_tmp;
listen_ctx.remote_addr[0] = (struct sockaddr *)storage;
listen_ctx.remote_addr[0] = (struct sockaddr *)(&storage);
listen_ctx.timeout = timeout; listen_ctx.timeout = timeout;
listen_ctx.iface = NULL; listen_ctx.iface = NULL;
listen_ctx.mptcp = mptcp; listen_ctx.mptcp = mptcp;
@ -1764,7 +1764,7 @@ start_ss_local_server(profile_t profile)
// Setup UDP // Setup UDP
if (mode != TCP_ONLY) { if (mode != TCP_ONLY) {
LOGI("udprelay enabled"); LOGI("udprelay enabled");
struct sockaddr *addr = (struct sockaddr *)storage;
struct sockaddr *addr = (struct sockaddr *)(&storage);
init_udprelay(local_addr, local_port_str, addr, init_udprelay(local_addr, local_port_str, addr,
get_sockaddr_len(addr), mtu, crypto, timeout, NULL); get_sockaddr_len(addr), mtu, crypto, timeout, NULL);
} }
@ -1785,20 +1785,16 @@ start_ss_local_server(profile_t profile)
} }
// Clean up // Clean up
if (mode != TCP_ONLY) {
free_udprelay();
}
if (mode != UDP_ONLY) { if (mode != UDP_ONLY) {
ev_io_stop(loop, &listen_ctx.io); ev_io_stop(loop, &listen_ctx.io);
free_connections(loop); free_connections(loop);
close(listen_ctx.fd); close(listen_ctx.fd);
} }
ss_free(listen_ctx.remote_addr[0]);
ss_free(remote_addr_tmp);
if (mode != TCP_ONLY) {
free_udprelay();
}
// cannot reach here
return 0; return 0;
} }

Loading…
Cancel
Save