Browse Source

allow different destination addresses in UDP relay

pull/344/head
Max Lv 10 years ago
parent
commit
e980265bde
1 changed files with 13 additions and 5 deletions
  1. 18
      src/udprelay.c

18
src/udprelay.c

@ -181,7 +181,7 @@ static char *hash_key(const int af, const struct sockaddr_storage *addr)
return (char *)enc_md5((const uint8_t *)key, key_len, NULL);
}
#if defined(UDPRELAY_REDIR)
#if defined(UDPRELAY_REDIR) || defined(UDPRELAY_REMOTE)
static int construct_udprealy_header(const struct sockaddr_storage *in_addr,
char *addr_header) {
@ -635,12 +635,13 @@ static void remote_recv_cb(EV_P_ ev_io *w, int revents)
LOGI("[udp] remote receive a packet");
}
struct sockaddr src_addr;
struct sockaddr_storage src_addr;
socklen_t src_addr_len = sizeof(src_addr);
memset(&src_addr, 0, src_addr_len);
char *buf = malloc(BUF_SIZE);
// recv
ssize_t buf_len = recvfrom(remote_ctx->fd, buf, BUF_SIZE, 0, &src_addr, &src_addr_len);
ssize_t buf_len = recvfrom(remote_ctx->fd, buf, BUF_SIZE, 0, (struct sockaddr *)&src_addr, &src_addr_len);
if (buf_len == -1) {
// error on recv
@ -696,12 +697,19 @@ static void remote_recv_cb(EV_P_ ev_io *w, int revents)
#ifdef UDPRELAY_REMOTE
unsigned int addr_header_len = remote_ctx->addr_header_len;
char addr_header_buf[256];
char *addr_header = remote_ctx->addr_header;
int addr_header_len = remote_ctx->addr_header_len;
if (remote_ctx->af == AF_INET || remote_ctx->af == AF_INET6) {
addr_header_len = construct_udprealy_header(&src_addr, addr_header_buf);
addr_header = addr_header_buf;
}
// Construct packet
buf = realloc(buf, buf_len + addr_header_len);
memmove(buf + addr_header_len, buf, buf_len);
memcpy(buf, remote_ctx->addr_header, addr_header_len);
memcpy(buf, addr_header, addr_header_len);
buf_len += addr_header_len;
buf = ss_encrypt_all(BUF_SIZE, buf, &buf_len, server_ctx->method);

Loading…
Cancel
Save