Example #1
0
 public override void init()
 {
     try
     {
         io = new IO();
         if (lport == -1)
         {
             Class c = Class.forName(target);
             ForwardedTCPIPDaemon daemon = (ForwardedTCPIPDaemon)c.newInstance();
             daemon.setChannel(this);
             Object[] foo = getPort(session, rport);
             daemon.setArg((Object[])foo[3]);
             new Thread(daemon).start();
             connected = true;
             return;
         }
         else
         {
             Socket socket = (factory == null) ?
                             new Socket(target, lport) :
                             factory.createSocket(target, lport);
             socket.setTcpNoDelay(true);
             io.setInputStream(socket.getInputStream());
             io.setOutputStream(socket.getOutputStream());
             connected = true;
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("target={0},port={1}", target, lport);
         Console.WriteLine(e);
     }
 }
        public override void init()
        {
            try
            {
                io = new IO();
                if (lport == -1)
                {
                    ForwardedTCPIPDaemon daemon = (ForwardedTCPIPDaemon)Activator.CreateInstance(Type.GetType(target));
                    daemon.setChannel(this);
                    Object[] foo = getPort(session, rport);
                    daemon.setArg((Object[])foo[3]);
                    new System.Threading.Thread(daemon.run).Start();
                    connected = true;
                    return;
                }
                else
                {
                    Socket socket;

                    if (factory == null)
                    {
                        var ep = new IPEndPoint(Dns.GetHostEntry(target).AddressList[0], lport);
                        socket = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                        socket.Connect(ep);
                    }
                    else
                    {
                        socket = factory.createSocket(target, lport);
                    }

                    socket.NoDelay = true;

                    io.setInputStream(new NetworkStream(socket));
                    io.setOutputStream(new NetworkStream(socket));
                    connected = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("target={0},port={1}", target, lport);
                Console.WriteLine(e);
            }
        }
        public override void run()
        {
            try
            {
                if (lport == -1)
                {
                    Type c = Type.GetType(target);
                    daemon = (ForwardedTCPIPDaemon)c.newInstance();

                    PipedMemoryStream Out = new PipedMemoryStream(32 * 1024);
                    /*
                    PipedOutputStream Out = new PipedOutputStream();
                    io.setInputStream(new PassiveInputStream(Out
                                                             , 32 * 1024
                                                             ), false);
                    */
                    io.setInputStream(Out);
                    daemon.setChannel(this, getInputStream(), Out);
                    object[] foo = getPort(getSession(), rport);
                    daemon.setArg((object[])foo[3]);

                    new Thread(new ThreadStart(daemon.run)).Start();
                }
                else
                {
                    socket = (factory == null) ?
                       Util.createSocket(target, lport, TIMEOUT) :
                      factory.createSocket(target, lport);
                    socket.NoDelay=true;
                    io.setInputStream(socket.GetStream());
                    io.setOutputStream(socket.GetStream());
                }
                sendOpenConfirmation();
            }
            catch //(Exception e)
            {
                sendOpenFailure(SSH_OPEN_ADMINISTRATIVELY_PROHIBITED);
                close = true;
                disconnect();
                return;
            }

            thread = Thread.CurrentThread;
            Buffer buf = new Buffer(rmpsize);
            Packet packet = new Packet(buf);
            int i = 0;
            try
            {
                while (thread != null &&
                      io != null &&
                      io.In != null)
                {
                    i = io.In.Read(buf.buffer,
                                 14,
                                 buf.buffer.Length - 14
                                 - 32 - 20 // padding and mac
                                 );
                    if (i <= 0)
                    {
                        eof();
                        break;
                    }
                    packet.reset();
                    if (close) break;
                    buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
                    buf.putInt(recipient);
                    buf.putInt(i);
                    buf.skip(i);
                    getSession().write(packet, this, i);
                }
            }
            catch //(Exception e)
            {
                //Console.Error.WriteLine(e);
            }
            //thread=null;
            //eof();
            disconnect();
        }
        public override void run()
        {
            try
            {
                if (lport == -1)
                {
                    Type c = Type.GetType(target);
                    daemon = (ForwardedTCPIPDaemon)c.newInstance();

                    PipedMemoryStream Out = new PipedMemoryStream(32 * 1024);

                    /*
                     * PipedOutputStream Out = new PipedOutputStream();
                     * io.setInputStream(new PassiveInputStream(Out
                     *                                       , 32 * 1024
                     *                                       ), false);
                     */
                    io.setInputStream(Out);
                    daemon.setChannel(this, getInputStream(), Out);
                    object[] foo = getPort(getSession(), rport);
                    daemon.setArg((object[])foo[3]);

                    new Thread(new ThreadStart(daemon.run)).Start();
                }
                else
                {
                    socket = (factory == null) ?
                             Util.createSocket(target, lport, TIMEOUT) :
                             factory.createSocket(target, lport);
                    socket.NoDelay = true;
                    io.setInputStream(socket.GetStream());
                    io.setOutputStream(socket.GetStream());
                }
                sendOpenConfirmation();
            }
            catch //(Exception e)
            {
                sendOpenFailure(SSH_OPEN_ADMINISTRATIVELY_PROHIBITED);
                close = true;
                disconnect();
                return;
            }

            thread = Thread.CurrentThread;
            Buffer buf    = new Buffer(rmpsize);
            Packet packet = new Packet(buf);
            int    i      = 0;

            try
            {
                while (thread != null &&
                       io != null &&
                       io.In != null)
                {
                    i = io.In.Read(buf.buffer,
                                   14,
                                   buf.buffer.Length - 14
                                   - 32 - 20 // padding and mac
                                   );
                    if (i <= 0)
                    {
                        eof();
                        break;
                    }
                    packet.reset();
                    if (close)
                    {
                        break;
                    }
                    buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
                    buf.putInt(recipient);
                    buf.putInt(i);
                    buf.skip(i);
                    getSession().write(packet, this, i);
                }
            }
            catch //(Exception e)
            {
                //Console.Error.WriteLine(e);
            }
            //thread=null;
            //eof();
            disconnect();
        }