Browse Source

fix redir

pull/51/head
Max Lv 10 years ago
parent
commit
b2df5a4c26
2 changed files with 11 additions and 11 deletions
  1. 20
      src/redir.c
  2. 2
      src/redir.h

20
src/redir.c

@ -369,18 +369,18 @@ static void remote_send_cb (EV_P_ ev_io *w, int revents)
ev_timer_stop(EV_A_ &remote_send_ctx->watcher);
// send destaddr
char *addr_to_send = malloc(BUF_SIZE);
char *ss_addr_to_send = malloc(BUF_SIZE);
ssize_t addr_len = 0;
addr_to_send[addr_len++] = 1;
ss_addr_to_send[addr_len++] = 1;
// handle IP V4 only
size_t in_addr_len = sizeof(struct in_addr);
memcpy(addr_to_send + addr_len, &server->destaddr.sin_addr, in_addr_len);
memcpy(ss_addr_to_send + addr_len, &server->destaddr.sin_addr, in_addr_len);
addr_len += in_addr_len;
memcpy(addr_to_send + addr_len, &server->destaddr.sin_port, 2);
memcpy(ss_addr_to_send + addr_len, &server->destaddr.sin_port, 2);
addr_len += 2;
addr_to_send = ss_encrypt(BUF_SIZE, addr_to_send, &addr_len, server->e_ctx);
if (addr_to_send == NULL)
ss_addr_to_send = ss_encrypt(BUF_SIZE, ss_addr_to_send, &addr_len, server->e_ctx);
if (ss_addr_to_send == NULL)
{
LOGE("invalid password or cipher");
close_and_free_remote(EV_A_ remote);
@ -388,8 +388,8 @@ static void remote_send_cb (EV_P_ ev_io *w, int revents)
return;
}
int s = send(remote->fd, addr_to_send, addr_len, 0);
free(addr_to_send);
int s = send(remote->fd, ss_addr_to_send, addr_len, 0);
free(ss_addr_to_send);
if (s < addr_len)
{
@ -669,7 +669,7 @@ int main (int argc, char **argv)
char *conf_path = NULL;
int remote_num = 0;
addr_t remote_addr[MAX_REMOTE_NUM];
ss_addr_t remote_addr[MAX_REMOTE_NUM];
char *remote_port = NULL;
opterr = 0;
@ -777,7 +777,7 @@ int main (int argc, char **argv)
// Setup proxy context
struct listen_ctx listen_ctx;
listen_ctx.remote_num = remote_num;
listen_ctx.remote_addr = malloc(sizeof(addr_t) * remote_num);
listen_ctx.remote_addr = malloc(sizeof(ss_addr_t) * remote_num);
while (remote_num > 0)
{
int index = --remote_num;

2
src/redir.h

@ -8,7 +8,7 @@
struct listen_ctx
{
ev_io io;
addr_t *remote_addr;
ss_addr_t *remote_addr;
int remote_num;
int timeout;
int fd;

Loading…
Cancel
Save