Let a Windows UDP service bind the socket it answers from

A UDP service on Windows binds a second socket to the address it listens on,
so a reply leaves the port the client sent to. Windows only allows that when
both sockets ask for it, and the listening socket was never asked, so the
bind failed and dnspr answered nothing at all on Windows.

Ask for it on the listening socket of a UDP service, and there only: the
reason it is withheld otherwise, that another local process could take a
listening port, is unchanged for everything else.
This commit is contained in:
Vladimir Dubrovin 2026-08-26 16:55:37 +03:00
parent 36979639b7
commit 0df93bfab7

View File

@ -830,6 +830,14 @@ int MODULEMAINFUNC (int argc, char** argv){
#ifndef _WIN32
opt = 1;
if(srv.so._setsockopt(srv.so.state, sock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int)))perror("setsockopt()");
#else
/* A UDP service on Windows answers from a second socket bound to
the address it listens on, and Windows only allows that bind
when both sockets ask for it. */
if(isudp){
opt = 1;
if(srv.so._setsockopt(srv.so.state, sock, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int)))perror("setsockopt()");
}
#endif
#ifdef SO_REUSEPORT
opt = 1;