1 2 package ch.ethz.ssh2.channel; 3 4 import java.io.IOException ; 5 import java.net.Socket ; 6 7 import ch.ethz.ssh2.log.Logger; 8 9 15 public class RemoteAcceptThread extends Thread 16 { 17 private static final Logger log = Logger.getLogger(RemoteAcceptThread.class); 18 19 Channel c; 20 21 String remoteConnectedAddress; 22 int remoteConnectedPort; 23 String remoteOriginatorAddress; 24 int remoteOriginatorPort; 25 String targetAddress; 26 int targetPort; 27 28 Socket s; 29 30 public RemoteAcceptThread(Channel c, String remoteConnectedAddress, int remoteConnectedPort, 31 String remoteOriginatorAddress, int remoteOriginatorPort, String targetAddress, int targetPort) 32 { 33 this.c = c; 34 this.remoteConnectedAddress = remoteConnectedAddress; 35 this.remoteConnectedPort = remoteConnectedPort; 36 this.remoteOriginatorAddress = remoteOriginatorAddress; 37 this.remoteOriginatorPort = remoteOriginatorPort; 38 this.targetAddress = targetAddress; 39 this.targetPort = targetPort; 40 41 if (log.isEnabled()) 42 log.log(20, "RemoteAcceptThread: " + remoteConnectedAddress + "/" + remoteConnectedPort + ", R: " 43 + remoteOriginatorAddress + "/" + remoteOriginatorPort); 44 } 45 46 public void run() 47 { 48 try 49 { 50 c.cm.sendOpenConfirmation(c); 51 52 s = new Socket (targetAddress, targetPort); 53 54 StreamForwarder r2l = new StreamForwarder(c, null, null, c.getStdoutStream(), s.getOutputStream(), 55 "RemoteToLocal"); 56 StreamForwarder l2r = new StreamForwarder(c, null, null, s.getInputStream(), c.getStdinStream(), 57 "LocalToRemote"); 58 59 60 61 r2l.setDaemon(true); 62 r2l.start(); 63 l2r.run(); 64 65 while (r2l.isAlive()) 66 { 67 try 68 { 69 r2l.join(); 70 } 71 catch (InterruptedException e) 72 { 73 } 74 } 75 76 77 78 c.cm.closeChannel(c, "EOF on both streams reached.", true); 79 s.close(); 80 } 81 catch (IOException e) 82 { 83 log.log(50, "IOException in proxy code: " + e.getMessage()); 84 85 try 86 { 87 c.cm.closeChannel(c, "IOException in proxy code (" + e.getMessage() + ")", true); 88 } 89 catch (IOException e1) 90 { 91 } 92 try 93 { 94 if (s != null) 95 s.close(); 96 } 97 catch (IOException e1) 98 { 99 } 100 } 101 } 102 } 103 | Popular Tags |