using System; namespace Renci.SshNet.Messages.Connection { /// /// Used to open "forwarded-tcpip" channel type /// internal class ForwardedTcpipChannelInfo : ChannelOpenInfo { private byte[] _connectedAddress; private byte[] _originatorAddress; /// /// Initializes a new instance of the class from the /// specified data. /// /// is null. public ForwardedTcpipChannelInfo(byte[] data) { Load(data); } /// /// Initializes a new instance with the specified connector /// address and port, and originator address and port. /// public ForwardedTcpipChannelInfo(string connectedAddress, uint connectedPort, string originatorAddress, uint originatorPort) { ConnectedAddress = connectedAddress; ConnectedPort = connectedPort; OriginatorAddress = originatorAddress; OriginatorPort = originatorPort; } /// /// Specifies channel open type /// public const string NAME = "forwarded-tcpip"; /// /// Gets the type of the channel to open. /// /// /// The type of the channel to open. /// public override string ChannelType { get { return NAME; } } /// /// Gets the connected address. /// public string ConnectedAddress { get { return Utf8.GetString(_connectedAddress, 0, _connectedAddress.Length); } private set { _connectedAddress = Utf8.GetBytes(value); } } /// /// Gets the connected port. /// public uint ConnectedPort { get; private set; } /// /// Gets the originator address. /// public string OriginatorAddress { get { return Utf8.GetString(_originatorAddress, 0, _originatorAddress.Length); } private set { _originatorAddress = Utf8.GetBytes(value); } } /// /// Gets the originator port. /// public uint OriginatorPort { get; private set; } /// /// Gets the size of the message in bytes. /// /// /// The size of the messages in bytes. /// protected override int BufferCapacity { get { var capacity = base.BufferCapacity; capacity += 4; // ConnectedAddress length capacity += _connectedAddress.Length; // ConnectedAddress capacity += 4; // ConnectedPort capacity += 4; // OriginatorAddress length capacity += _originatorAddress.Length; // OriginatorAddress capacity += 4; // OriginatorPort return capacity; } } /// /// Called when type specific data need to be loaded. /// protected override void LoadData() { base.LoadData(); _connectedAddress = ReadBinary(); ConnectedPort = ReadUInt32(); _originatorAddress = ReadBinary(); OriginatorPort = ReadUInt32(); } /// /// Called when type specific data need to be saved. /// protected override void SaveData() { base.SaveData(); WriteBinaryString(_connectedAddress); Write(ConnectedPort); WriteBinaryString(_originatorAddress); Write(OriginatorPort); } } }