Report closed ports as closed on Windows - #498
Merged
Merged
Conversation
|
Site preview: https://pr-498.netscli-site-preview.pages.dev Built from 540f7fd with Production is unaffected: netscli.com is served from GitHub Pages via |
Windows retries a SYN answered with a RST for about 2 s before connect() fails with WSAECONNREFUSED. The scanner's default timeout is 500 ms, so every closed port timed out first and read as filtered. Connect through a socket with SYN retransmissions off (SIO_TCP_INITIAL_RTO, MaxSynRetransmissions = TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS), which makes the first RST final. Without retransmissions Windows gives up after the initial RTO (1 s by default), so set that to the caller's timeout too. The closed-port test accepted filtered, which is how this went unnoticed; it now requires closed within 500 ms and fails without the ioctl.
fstubner
force-pushed
the
fix/windows-closed-ports
branch
from
October 2, 2026 22:41
07f2f28 to
cb94089
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Windows every closed port came back as filtered. Windows retries a SYN that was answered with a RST for about 2 s before
connect()reports the refusal, and the scanner stops waiting at 500 ms.The scanner now connects through a socket with SYN retransmissions turned off (
SIO_TCP_INITIAL_RTO), so the first RST is final. With no retransmissions Windows gives up after the initial retransmission timeout, 1 s by default, so that is set to the scan timeout as well; otherwise a longer timeout would be cut to 1 s.Measured (Windows 11, release build,
scan -p 1-1024)Single connects to a closed port: 2025 to 2047 ms before, 0 to 5 ms after. A port that drops packets still times out at the requested timeout (checked at 300 ms and 3000 ms).
Tests
The closed-port test allowed
Filtered, which is how this went unnoticed. It now requiresClosedwithin 500 ms. With the ioctl commented out it fails (left: Filtered, right: Closed).Linux and macOS are unchanged apart from the connect going through
TcpSocketinstead ofTcpStream::connect.