Repository navigation
Conversation
ForwardedPortLocal, ForwardedPortDynamic and ForwardedPortRemote resolve the
bound host with Dns.GetHostAddresses, which throws ArgumentException for 0.0.0.0
and :: ("IPv4 address 0.0.0.0 and IPv6 address ::0 are unspecified addresses that
cannot be used as a target address"). The ports therefore could not be bound to
all interfaces, even though Socket.Bind supports it.
Parse IP literals directly and only fall back to name resolution for host names.
Fixes sshnet#525
gluoncat
requested review from
Rob-Hague,
WojciechNagorski and
drieseng
as code owners
November 30, 2026 09:33
This branch has not been deployed
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.
Summary
ForwardedPortLocal,ForwardedPortDynamicandForwardedPortRemoteresolve the bound host viaDns.GetHostAddresses. .NET rejects the unspecified addresses for name resolution, so0.0.0.0/::can never be used as the bound host — even though
Socket.Bindsupports them:Reproduction (fails with the exception above):
The only workaround today is to construct
ForwardedPortRemotethrough itsIPAddressoverload(
ForwardedPortLocalandForwardedPortDynamichave none) or to enumerate the local interfaceaddresses and start one forward per address.
Change
Parse the bound host as an IP literal first, and only fall back to name resolution for host names:
Applied to:
ForwardedPortLocal.InternalStart()ForwardedPortDynamic.InternalStart()ForwardedPortRemote(string boundHost, uint boundPort, string host, uint port)Host names still go through
Dns.GetHostAddresses, and an empty bound host takes the previous codepath unchanged (
IPAddress.TryParse("")returnsfalse). No public API change; theForwardedPortRemotetarget host is untouched.
Tests
Added
ForwardedPortLocalTest_Start_WildcardBoundHost: starts aForwardedPortLocalwith bound host0.0.0.0on an ephemeral port against a mocked session, and asserts the port is started and has anon-zero bound port. It fails with the
ArgumentExceptionabove before the change.Notes
ssh -R 0.0.0.0:port:host:port-style remote forwards.Fixes #525