Fix dnspr for Windows

(cherry picked from commit a194f207ba)
This commit is contained in:
Vladimir Dubrovin committed 2026-08-26 16:48:09 +03:00
1 parent 3ff0f8b7ab
commit efa6f6560c
7 files changed
+59 -12

No files matched your search

+5 -2
View File
@@ -45,7 +45,7 @@ void * dnsprchild(struct clientparam* param) {
memcpy(buf, param->srv->udpbuf, i);
_3proxy_sem_unlock(udpinit);
semlocked = 0;
#ifdef _WIN32
#if defined(_WIN32) && !defined(SHARE_UDP_SOCKET)
if((param->clisock=param->srv->so._socket(param->sostate, AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET) {
RETURN(818);
}
@@ -56,6 +56,8 @@ void * dnsprchild(struct clientparam* param) {
}
#else
/* The reply has to come from the address the query was sent to, which
is the listening socket. */
param->clisock = param->srv->srvsock;
#endif
@@ -217,7 +219,8 @@ CLEANRET:
}
if(bbuf)free(bbuf);
if(host)free(host);
#ifndef _WIN32
#if !defined(_WIN32) || defined(SHARE_UDP_SOCKET)
/* The socket belongs to the service, so the caller must not close it. */
param->clisock = INVALID_SOCKET;
#endif
return (NULL);
+15
View File
@@ -152,6 +152,21 @@ void daemonize(void);
#endif
#endif
/* A UDP service answers from the address the client sent to, so the reply has
to leave the listening socket. Sharing that socket with the request handler
is the simple way, and what every Unix build does.
Older Windows cannot have two operations in flight on one socket, so a
build for it binds a second socket to the same address instead, which needs
SO_REUSEADDR on the listening socket as well. A build for those versions
asks for that with NO_SHARE_UDP_SOCKET, as Makefile.watcom does.
*/
#ifndef SHARE_UDP_SOCKET
#ifndef NO_SHARE_UDP_SOCKET
#define SHARE_UDP_SOCKET
#endif
#endif
#ifndef _WIN32
size_t threadstacksize(int extra);
#endif
+11
View File
@@ -835,10 +835,21 @@ int MODULEMAINFUNC (int argc, char** argv){
port there, and it only allows another local process to bind the same
address and port, with undefined behaviour as to which socket receives the
connections. Use -olSO_EXCLUSIVEADDRUSE to prevent that instead.
A Windows build which does not share the listening socket is the exception:
its UDP services bind a second socket to the same address to answer from,
and Windows only allows that when both sockets ask for it.
*/
#ifndef _WIN32
opt = 1;
if(srv.so._setsockopt(srv.so.state, sock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int)))perror("setsockopt()");
#else
#ifndef SHARE_UDP_SOCKET
if(isudp){
opt = 1;
if(srv.so._setsockopt(srv.so.state, sock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int)))perror("setsockopt()");
}
#endif
#endif
#ifdef SO_REUSEPORT
opt = 1;