diff --git a/src/udprelay.c b/src/udprelay.c index 7d4d2d5b..5ea08f7f 100644 --- a/src/udprelay.c +++ b/src/udprelay.c @@ -622,7 +622,6 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) if (remote_ctx == NULL) { - struct addrinfo hints; struct addrinfo *result; @@ -667,8 +666,8 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) freeaddrinfo(result); } - buf_len -= 3; - memmove(buf, buf + 3, buf_len); + buf_len -= offset; + memmove(buf, buf + offset, buf_len); buf = ss_encrypt_all(BUF_SIZE, buf, &buf_len, server_ctx->method); @@ -681,9 +680,6 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) #else - buf_len -= (offset + addr_header_len); - memmove(buf, buf + (offset + addr_header_len), buf_len); - if (remote_ctx == NULL) { struct addrinfo hints; @@ -701,7 +697,8 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) goto CLEAN_UP; } - struct query_ctx *query_ctx = new_query_ctx(query, buf, buf_len); + struct query_ctx *query_ctx = new_query_ctx(query, buf + addr_header_len, + buf_len - addr_header_len); query_ctx->server_ctx = server_ctx; query_ctx->addr_header_len = addr_header_len; query_ctx->src_addr = src_addr; @@ -713,7 +710,8 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) else { - int s = sendto(remote_ctx->fd, buf, buf_len, 0, &remote_ctx->dst_addr, sizeof(remote_ctx->dst_addr)); + int s = sendto(remote_ctx->fd, buf + addr_header_len, + buf_len - addr_header_len, 0, &remote_ctx->dst_addr, sizeof(remote_ctx->dst_addr)); if (s == -1) {