1
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
3
Copyright (c) 2002-2012 ymnk, JCraft,Inc. All rights reserved.
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are met:
8
1. Redistributions of source code must retain the above copyright notice,
9
this list of conditions and the following disclaimer.
11
2. Redistributions in binary form must reproduce the above copyright
12
notice, this list of conditions and the following disclaimer in
13
the documentation and/or other materials provided with the distribution.
15
3. The names of the authors may not be used to endorse or promote products
16
derived from this software without specific prior written permission.
18
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
package com.jcraft.jsch;
34
public class ChannelDirectTCPIP extends Channel{
36
static private final int LOCAL_WINDOW_SIZE_MAX=0x20000;
37
static private final int LOCAL_MAXIMUM_PACKET_SIZE=0x4000;
38
static private final byte[] _type = Util.str2byte("direct-tcpip");
42
String originator_IP_address="127.0.0.1";
43
int originator_port=0;
48
setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
49
setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
50
setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
57
public void connect(int connectTimeout) throws JSchException{
58
this.connectTimeout=connectTimeout;
60
Session _session=getSession();
61
if(!_session.isConnected()){
62
throw new JSchException("session is down");
66
thread=new Thread(this);
67
thread.setName("DirectTCPIP thread "+_session.getHost());
68
if(_session.daemon_thread){
69
thread.setDaemon(_session.daemon_thread);
81
if (e instanceof JSchException) {
82
throw (JSchException) e;
92
Buffer buf=new Buffer(rmpsize);
93
Packet packet=new Packet(buf);
94
Session _session=getSession();
97
while(isConnected() &&
101
i=io.in.read(buf.buffer,
104
-Session.buffer_margin
111
buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
112
buf.putInt(recipient);
118
_session.write(packet, this, i);
127
public void setInputStream(InputStream in){
128
io.setInputStream(in);
130
public void setOutputStream(OutputStream out){
131
io.setOutputStream(out);
134
public void setHost(String host){this.host=host;}
135
public void setPort(int port){this.port=port;}
136
public void setOrgIPAddress(String foo){this.originator_IP_address=foo;}
137
public void setOrgPort(int foo){this.originator_port=foo;}
139
protected Packet genChannelOpenPacket(){
140
Buffer buf = new Buffer(50 + // 6 + 4*8 + 12
141
host.length() + originator_IP_address.length() +
142
Session.buffer_margin);
143
Packet packet = new Packet(buf);
144
// byte SSH_MSG_CHANNEL_OPEN(90)
145
// string channel type //
146
// uint32 sender channel // 0
147
// uint32 initial window size // 0x100000(65536)
148
// uint32 maxmum packet size // 0x4000(16384)
150
buf.putByte((byte)90);
151
buf.putString(this.type);
155
buf.putString(Util.str2byte(host));
157
buf.putString(Util.str2byte(originator_IP_address));
158
buf.putInt(originator_port);