diff --git a/src/Renci.SshNet/ForwardedPortDynamic.cs b/src/Renci.SshNet/ForwardedPortDynamic.cs index 5b8ff9d2..4a85a0fa 100644 --- a/src/Renci.SshNet/ForwardedPortDynamic.cs +++ b/src/Renci.SshNet/ForwardedPortDynamic.cs @@ -40,7 +40,7 @@ namespace Renci.SshNet /// /// Gets the bound port. /// - public uint BoundPort { get; } + public uint BoundPort { get; private set; } private Socket _listener; private CountdownEvent _pendingChannelCountdown; @@ -168,6 +168,9 @@ namespace Renci.SshNet _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;