sshnet / sshnet/SSH.NET

Cannot listen to port on ALL interfaces "0.0.0.0"

Open
#525 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
993
Avg merge
9d 21h
Merged PRs (30d)
1

Description

I found that you cannot do a ForwardedPortLocal/Remote if the bound host is set to "0.0.0.0" or IPAddress.Any.ToString().
The .NET will throw an exception.

I think your problem is in the ForwardedPortLocal:InternalStart() method. I think when you create the IPEndPoint you should do:

IPEndPoint ipEndPoint;
if (this.BoundHost == IPAddress.Any.ToString()) // Or however you want to compare
ipEndPoint = new IPEndPoint(IPAddress.Any, (int) this.BoundPort);
else
ipEndPoint = new IPEndPoint(DnsAbstraction.GetHostAddresses(this.BoundHost)[0], (int) this.BoundPort);

Similarly, the constructor, ForwardedPortRemote(string boundHost, uint boundPort, string host, uint port)
creates the IPAddress of the bound host exaclty the same way, by calling Dns.GetHostAdresses().

I am not sure if you did this on purpose to try to NOT support IPAddress.Any, however, it is clear there are cases when this is needed, and in fact other libraries (SecureBlackBox) support it.

I see you allow boundHost to be string.Empty, but shouldn't then you be doing the conversion to IPAdress.Any directly?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ForwardedPortLocal:InternalStart() and the ForwardedPortRemote(string boundHost, uint boundPort, string host, uint port) constructor, then inspect how DnsAbstraction resolves the bound host before creating an IPEndPoint. The change is done when forwarding accepts "0.0.0.0" and an empty bound host without the reported .NET exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.