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