| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace Renci.SshNet.Messages.Connection |
| | | 4 | | { |
| | | 5 | | /// <summary> |
| | | 6 | | /// Used to open "direct-tcpip" channel type. |
| | | 7 | | /// </summary> |
| | | 8 | | internal sealed class DirectTcpipChannelInfo : ChannelOpenInfo |
| | | 9 | | { |
| | | 10 | | private byte[] _hostToConnect; |
| | | 11 | | private byte[] _originatorAddress; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Specifies channel open type. |
| | | 15 | | /// </summary> |
| | | 16 | | public const string NAME = "direct-tcpip"; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Gets the type of the channel to open. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <value> |
| | | 22 | | /// The type of the channel to open. |
| | | 23 | | /// </value> |
| | | 24 | | public override string ChannelType |
| | | 25 | | { |
| | 165 | 26 | | get { return NAME; } |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets the host to connect. |
| | | 31 | | /// </summary> |
| | | 32 | | public string HostToConnect |
| | | 33 | | { |
| | 63 | 34 | | get { return Utf8.GetString(_hostToConnect, 0, _hostToConnect.Length); } |
| | 129 | 35 | | private set { _hostToConnect = Utf8.GetBytes(value); } |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Gets the port to connect. |
| | | 40 | | /// </summary> |
| | 113 | 41 | | public uint PortToConnect { get; private set; } |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Gets the originator address. |
| | | 45 | | /// </summary> |
| | | 46 | | public string OriginatorAddress |
| | | 47 | | { |
| | 63 | 48 | | get { return Utf8.GetString(_originatorAddress, 0, _originatorAddress.Length); } |
| | 129 | 49 | | private set { _originatorAddress = Utf8.GetBytes(value); } |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// Gets the originator port. |
| | | 54 | | /// </summary> |
| | 113 | 55 | | public uint OriginatorPort { get; private set; } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Gets the size of the message in bytes. |
| | | 59 | | /// </summary> |
| | | 60 | | /// <value> |
| | | 61 | | /// The size of the messages in bytes. |
| | | 62 | | /// </value> |
| | | 63 | | protected override int BufferCapacity |
| | | 64 | | { |
| | | 65 | | get |
| | 46 | 66 | | { |
| | 46 | 67 | | var capacity = base.BufferCapacity; |
| | 46 | 68 | | capacity += 4; // HostToConnect length |
| | 46 | 69 | | capacity += _hostToConnect.Length; // HostToConnect |
| | 46 | 70 | | capacity += 4; // PortToConnect |
| | 46 | 71 | | capacity += 4; // OriginatorAddress length |
| | 46 | 72 | | capacity += _originatorAddress.Length; // OriginatorAddress |
| | 46 | 73 | | capacity += 4; // OriginatorPort |
| | 46 | 74 | | return capacity; |
| | 46 | 75 | | } |
| | | 76 | | } |
| | | 77 | | |
| | | 78 | | /// <summary> |
| | | 79 | | /// Initializes a new instance of the <see cref="DirectTcpipChannelInfo"/> class from the |
| | | 80 | | /// specified data. |
| | | 81 | | /// </summary> |
| | | 82 | | /// <exception cref="ArgumentNullException"><paramref name="data"/> is <see langword="null"/>.</exception> |
| | 3 | 83 | | public DirectTcpipChannelInfo(byte[] data) |
| | 3 | 84 | | { |
| | 3 | 85 | | Load(data); |
| | 3 | 86 | | } |
| | | 87 | | |
| | | 88 | | /// <summary> |
| | | 89 | | /// Initializes a new instance of the <see cref="DirectTcpipChannelInfo"/> class. |
| | | 90 | | /// </summary> |
| | | 91 | | /// <param name="hostToConnect">The host to connect.</param> |
| | | 92 | | /// <param name="portToConnect">The port to connect.</param> |
| | | 93 | | /// <param name="originatorAddress">The originator address.</param> |
| | | 94 | | /// <param name="originatorPort">The originator port.</param> |
| | 43 | 95 | | public DirectTcpipChannelInfo(string hostToConnect, uint portToConnect, string originatorAddress, uint originato |
| | 43 | 96 | | { |
| | 43 | 97 | | HostToConnect = hostToConnect; |
| | 43 | 98 | | PortToConnect = portToConnect; |
| | 43 | 99 | | OriginatorAddress = originatorAddress; |
| | 43 | 100 | | OriginatorPort = originatorPort; |
| | 43 | 101 | | } |
| | | 102 | | |
| | | 103 | | /// <summary> |
| | | 104 | | /// Called when type specific data need to be loaded. |
| | | 105 | | /// </summary> |
| | | 106 | | protected override void LoadData() |
| | 3 | 107 | | { |
| | 3 | 108 | | base.LoadData(); |
| | | 109 | | |
| | 3 | 110 | | _hostToConnect = ReadBinary(); |
| | 3 | 111 | | PortToConnect = ReadUInt32(); |
| | 3 | 112 | | _originatorAddress = ReadBinary(); |
| | 3 | 113 | | OriginatorPort = ReadUInt32(); |
| | 3 | 114 | | } |
| | | 115 | | |
| | | 116 | | /// <summary> |
| | | 117 | | /// Called when type specific data need to be saved. |
| | | 118 | | /// </summary> |
| | | 119 | | protected override void SaveData() |
| | 46 | 120 | | { |
| | 46 | 121 | | base.SaveData(); |
| | | 122 | | |
| | 46 | 123 | | WriteBinaryString(_hostToConnect); |
| | 46 | 124 | | Write(PortToConnect); |
| | 46 | 125 | | WriteBinaryString(_originatorAddress); |
| | 46 | 126 | | Write(OriginatorPort); |
| | 46 | 127 | | } |
| | | 128 | | } |
| | | 129 | | } |