Fix telnet server failing to connect on Windows#3170
Open
Moriarteh wants to merge 2 commits intoKSP-KOS:developfrom
Open
Fix telnet server failing to connect on Windows#3170Moriarteh wants to merge 2 commits intoKSP-KOS:developfrom
Moriarteh wants to merge 2 commits intoKSP-KOS:developfrom
Conversation
Turns out, binding to 127.0.0.1 specifically can fail on Windows if anything decides to get between you and your own computer. Npcap (hello Wireshark users) is a known offender, but firewalls and other network drivers can pull the same trick. The fix: bind to 0.0.0.0 instead, which sidesteps whatever is lurking on the loopback interface. But since we don't actually want the whole neighbourhood connecting to our kOS terminal, non-loopback connections are rejected when the user configured loopback mode. Works with or without Npcap. Works on systems that were never broken. Mostly just works, which is a nice change for networking.
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.
Fixes #3171
The Problem
On some Windows systems, the kOS telnet server listens successfully but clients can never connect — the connection hangs at "Trying 127.0.0.1..." indefinitely. No error, no rejection, just silence.
The root cause: when
TcpListenerbinds specifically toIPAddress.Loopback(127.0.0.1), certain software that hooks the Windows loopback network interface can intercept the traffic before it reaches the application. The most common culprit is Npcap (bundled with Wireshark and Nmap), which installs its own "Npcap Loopback Adapter" — but firewalls and other network drivers can cause the same issue.This has likely been the cause behind reports like #2937, where users saw the server listening but could never connect.
The Fix
Two changes to
TelnetMainServer.cs:Bind to
IPAddress.Anyinstead ofIPAddress.Loopbackwhen the user has configured loopback mode. This routes connections through the general network stack instead of the dedicated loopback interface, bypassing whatever is intercepting it.Reject non-loopback connections when in loopback mode. Since binding to
0.0.0.0also listens on LAN interfaces, we explicitly check the remote address and reject anything that isn't loopback. This preserves the user's security intent.The fix is transparent on unaffected systems —
IPAddress.Anyaccepts loopback connections identically toIPAddress.Loopback.Testing
Checklist