Skip to content

Update bound port on ForwardedPortDynamic after connection (in case original was passed as zero) #1577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Renci.SshNet/ForwardedPortDynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ForwardedPortDynamic : ForwardedPort
/// <summary>
/// Gets the bound port.
/// </summary>
public uint BoundPort { get; }
public uint BoundPort { get; private set; }

private Socket _listener;
private CountdownEvent _pendingChannelCountdown;
Expand Down Expand Up @@ -168,6 +168,9 @@ private void InternalStart()
_listener.Bind(ep);
_listener.Listen(5);

// update bound port (in case original was passed as zero)
BoundPort = (uint)((IPEndPoint)_listener.LocalEndPoint).Port;

Session.ErrorOccured += Session_ErrorOccured;
Session.Disconnected += Session_Disconnected;

Expand Down