Fix SOCKS CONNECT and BIND replies reporting the client side address

Without -Ne, the reply to CONNECT and BIND named the local address of the
client's connection to the proxy instead of the socket towards the
destination: the branch meant for UDP ASSOCIATE also took these. A BIND
client was told the proxy's own port and the peer could never reach the
listener. Introduced with -Ne / -Ni (0c8be90).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vladimir Dubrovin 2026-10-12 18:03:07 +03:00
parent a20f646169
commit c14393cfe4

View File

@ -268,12 +268,17 @@ CLEANRET:
int repcode; int repcode;
sasize = sizeof(sin); sasize = sizeof(sin);
if(command != 3 && param->remsock != INVALID_SOCKET) param->srv->so._getsockname(param->sostate, param->remsock, (struct sockaddr *)&sin, &sasize); /* CONNECT and BIND report the address of the socket towards the
if(command != 3 && !SAISNULL(&param->srv->extNat)){ destination, UDP ASSOCIATE the one the client sends its datagrams
uint16_t port; to, as does a request which never got a socket of its own */
port = *SAPORT(&sin); if(command != 3 && param->remsock != INVALID_SOCKET){
sin = param->srv->extNat; param->srv->so._getsockname(param->sostate, param->remsock, (struct sockaddr *)&sin, &sasize);
*SAPORT(&sin) = port; if(!SAISNULL(&param->srv->extNat)){
uint16_t port;
port = *SAPORT(&sin);
sin = param->srv->extNat;
*SAPORT(&sin) = port;
}
} }
else { else {
param->srv->so._getsockname(param->sostate, param->clisock, (struct sockaddr *)&sin, &sasize); param->srv->so._getsockname(param->sostate, param->clisock, (struct sockaddr *)&sin, &sasize);