One more crazy option seems to set the socket into a refuse always mode, see setsockopt
call with SO_PAUSE_ACCEPT
parameter.
Use this option for listening sockets. When the option is set, the socket responds to all incoming connections with an RST rather than accepting them.
I wonder if notification events would still be passed to the application about the connection attempts then (services like WSAEventSelect( , , FD_ACCEPT)
and WSAAsyncSelect( , , FD_ACCEPT)
) for making application like "port knocking", where mere attempts matters.
UPD. at least with Win10 FD_ACCEPT
notifications indeed cease to come on a "paused" socket. Neither come FD_CONNECT
or FD_CLOSE
.
Also, it seems the clients then are getting time-outed rather than outright rejected. The paused
connection fails in somehow more explicit way (telnet reports the rejection outright, while it waits for any user input to send when faces WSAAccept
-based rejection) but after a significant delay (seen in Firefox, telnet always has 1-2 seconds delay of its own).
SysInternals TCPView though does not see any special state on such a listening socket.
UPD2. oops, i forgot to add SO_CONDITIONAL_ACCEPT
to socket options in between bind
and listen
. Now telnet (still slow to launch) does no more wait for user input. Firefox OTOH became much slower to report error (it makes about a dozen of attempts before giving up, and did it faster). Maybe it is related to the listen
-> WSAAsyncSelect
-> WndProc
-> WSAAccept
pipeline in the test server.
/etc/host.allow
file – Ginsburg