using System; namespace Renci.SshNet.Messages.Connection { /// /// Used to open "direct-tcpip" channel type /// internal class DirectTcpipChannelInfo : ChannelOpenInfo { private byte[] _hostToConnect; private byte[] _originatorAddress; /// /// Specifies channel open type /// public const string NAME = "direct-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 host to connect. /// public string HostToConnect { get { return Utf8.GetString(_hostToConnect, 0, _hostToConnect.Length); } private set { _hostToConnect = Utf8.GetBytes(value); } } /// /// Gets the port to connect. /// public uint PortToConnect { 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; // HostToConnect length capacity += _hostToConnect.Length; // HostToConnect capacity += 4; // PortToConnect capacity += 4; // OriginatorAddress length capacity += _originatorAddress.Length; // OriginatorAddress capacity += 4; // OriginatorPort return capacity; } } /// /// Initializes a new instance of the class from the /// specified data. /// /// is null. public DirectTcpipChannelInfo(byte[] data) { Load(data); } /// /// Initializes a new instance of the class. /// /// The host to connect. /// The port to connect. /// The originator address. /// The originator port. public DirectTcpipChannelInfo(string hostToConnect, uint portToConnect, string originatorAddress, uint originatorPort) { HostToConnect = hostToConnect; PortToConnect = portToConnect; OriginatorAddress = originatorAddress; OriginatorPort = originatorPort; } /// /// Called when type specific data need to be loaded. /// protected override void LoadData() { base.LoadData(); _hostToConnect = ReadBinary(); PortToConnect = ReadUInt32(); _originatorAddress = ReadBinary(); OriginatorPort = ReadUInt32(); } /// /// Called when type specific data need to be saved. /// protected override void SaveData() { base.SaveData(); WriteBinaryString(_hostToConnect); Write(PortToConnect); WriteBinaryString(_originatorAddress); Write(OriginatorPort); } } }