2
Copyright (c) 2006-2010 ymnk, JCraft,Inc. All rights reserved.
4
Redistribution and use in source and binary forms, with or without
5
modification, are permitted provided that the following conditions are met:
7
1. Redistributions of source code must retain the above copyright notice,
8
this list of conditions and the following disclaimer.
10
2. Redistributions in binary form must reproduce the above copyright
11
notice, this list of conditions and the following disclaimer in
12
the documentation and/or other materials provided with the distribution.
14
3. The names of the authors may not be used to endorse or promote products
15
derived from this software without specific prior written permission.
17
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
18
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
20
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
21
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
This code is based on jsch (http://www.jcraft.com/jsch).
29
All credit should go to the authors of jsch.
38
public class ChannelDirectTCPIP : Channel
40
private const int LOCAL_WINDOW_SIZE_MAX = unchecked((int)(0x20000));
42
private const int LOCAL_MAXIMUM_PACKET_SIZE = unchecked((int)(0x4000));
48
internal string originator_IP_address = "127.0.0.1";
50
internal int originator_port = 0;
52
public ChannelDirectTCPIP() : base()
54
SetLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
55
SetLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
56
SetLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
59
internal override void Init()
67
System.Console.Error.WriteLine(e);
71
/// <exception cref="NSch.JSchException"></exception>
72
public override void Connect()
76
Session _session = GetSession();
77
if (!_session.IsConnected())
79
throw new JSchException("session is down");
81
Buffer buf = new Buffer(150);
82
Packet packet = new Packet(buf);
84
// byte SSH_MSG_CHANNEL_OPEN(90)
85
// string channel type //
86
// uint32 sender channel // 0
87
// uint32 initial window size // 0x100000(65536)
88
// uint32 maxmum packet size // 0x4000(16384)
90
buf.PutByte(unchecked((byte)90));
91
buf.PutString(Util.Str2byte("direct-tcpip"));
95
buf.PutString(Util.Str2byte(host));
97
buf.PutString(Util.Str2byte(originator_IP_address));
98
buf.PutInt(originator_port);
99
_session.Write(packet);
103
while (this.GetRecipient() == -1 && _session.IsConnected() && retry > 0 && !eof_remote
107
Sharpen.Thread.Sleep(50);
114
if (!_session.IsConnected())
116
throw new JSchException("session is down");
118
if (retry == 0 || this.eof_remote)
120
throw new JSchException("channel is not opened.");
125
thread = new Sharpen.Thread(this);
126
thread.SetName("DirectTCPIP thread " + _session.GetHost());
127
if (_session.daemon_thread)
129
thread.SetDaemon(_session.daemon_thread);
139
if (e is JSchException)
141
throw (JSchException)e;
146
public override void Run()
148
Buffer buf = new Buffer(rmpsize);
149
Packet packet = new Packet(buf);
153
Session _session = GetSession();
154
while (IsConnected() && thread != null && io != null && io.@in != null)
156
i = io.@in.Read(buf.buffer, 14, buf.buffer.Length - 14 - 32 - 20);
168
buf.PutByte(unchecked((byte)Session.SSH_MSG_CHANNEL_DATA));
169
buf.PutInt(recipient);
172
_session.Write(packet, this, i);
181
//System.err.println("connect end");
182
public override void SetInputStream(InputStream @in)
184
io.SetInputStream(@in);
187
public override void SetOutputStream(OutputStream @out)
189
io.SetOutputStream(@out);
192
public virtual void SetHost(string host)
197
public virtual void SetPort(int port)
202
public virtual void SetOrgIPAddress(string foo)
204
this.originator_IP_address = foo;
207
public virtual void SetOrgPort(int foo)
209
this.originator_port = foo;