Exemple #1
0
        internal static PortWatcher getPort(Session session, String address, int lport)
        {
            InetAddress addr;

            try
            {
                addr = InetAddress.getByName(address);
            }
            catch (Exception uhe)
            {
                throw new JSchException("PortForwardingL: invalid address " + address + " specified.");
            }
            lock (pool)
            {
                for (int i = 0; i < pool.size(); i++)
                {
                    PortWatcher p = (PortWatcher)(pool.elementAt(i));
                    if (p.session == session && p.lport == lport)
                    {
                        if (p.boundaddress.isAnyLocalAddress() ||
                            p.boundaddress.equals(addr))
                        {
                            return(p);
                        }
                    }
                }
                return(null);
            }
        }
Exemple #2
0
 internal PortWatcher(Session session,
                      String address, int lport,
                      String host, int rport,
                      ServerSocketFactory factory)
 {
     this.session = session;
     this.lport   = lport;
     this.host    = host;
     this.rport   = rport;
     try
     {
         boundaddress = InetAddress.getByName(address);
         ss           = (factory == null) ?
                        new ServerSocket(lport, 0, boundaddress) :
                        factory.createServerSocket(lport, 0, boundaddress);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw new JSchException("PortForwardingL: local port " + address + ":" + lport + " cannot be bound.");
     }
 }