From efc3474d1b35baf031f8b40b948388b2d42792b8 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 8 Sep 2017 12:56:29 +0200 Subject: [PATCH] Add proper destination address when answering an UDP client. --- rinetd.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rinetd.c b/rinetd.c index e3f2488..5dce084 100644 --- a/rinetd.c +++ b/rinetd.c @@ -543,8 +543,17 @@ static void handleWrite(ConnectionInfo *cnx, Socket *socket, Socket *other_socke socket->fd = INVALID_SOCKET; return; } - int got = send(socket->fd, other_socket->buffer + socket->sentPos, - other_socket->recvPos - socket->sentPos, 0); + + struct sockaddr const *addr = NULL; + SOCKLEN_T addrlen = 0; + if (socket->proto == protoUdp && socket == &cnx->remote) { + addr = (struct sockaddr const*)&cnx->remoteAddress; + addrlen = (SOCKLEN_T)sizeof(cnx->remoteAddress); + } + + int got = sendto(socket->fd, other_socket->buffer + socket->sentPos, + other_socket->recvPos - socket->sentPos, 0, + addr, addrlen); if (got < 0) { if (GetLastError() == WSAEWOULDBLOCK) { return;