示例#1
0
        internal static PortWatcher getPort(Session session, String address, int lport)
        {
            IPAddress addr;

            try {
                addr = Dns.GetHostEntry(address).AddressList[0];
            }
            catch (Exception) {
                throw new SshClientException("PortForwardingL: invalid address " + address + " specified.");
            }
            lock (pool) {
                for (int i = 0; i < pool.Count; i++)
                {
                    PortWatcher p = (PortWatcher)(pool[i]);
                    if (p.session == session && p.lport == lport)
                    {
                        if (IPAddress.IsLoopback(p.boundaddress) ||
                            p.boundaddress.ToString().Equals(addr.ToString()))
                        {
                            return(p);
                        }
                    }
                }
                return(null);
            }
        }
示例#2
0
        internal static void delPort(Session session, String address, int lport)
        {
            PortWatcher pw = getPort(session, address, lport);

            if (pw == null)
            {
                throw new SshClientException("PortForwardingL: local port " + address + ":" + lport + " is not registered.");
            }
            pw.delete();
            pool.Remove(pw);
        }
示例#3
0
        internal static PortWatcher addPort(Session session, String address, int lport, String host, int rport, ITcpListenerFactory ssf)
        {
            if (getPort(session, address, lport) != null)
            {
                throw new SshClientException("PortForwardingL: local port " + address + ":" + lport + " is already registered.");
            }
            PortWatcher pw = new PortWatcher(session, address, lport, host, rport, ssf);

            pool.Add(pw);
            return(pw);
        }
示例#4
0
        internal static String[] getPortForwarding(Session session)
        {
            ArrayList foo = new ArrayList();

            lock (pool) {
                for (int i = 0; i < pool.Count; i++)
                {
                    PortWatcher p = (PortWatcher)(pool[i]);
                    if (p.session == session)
                    {
                        foo.Add(p.lport + ":" + p.host + ":" + p.rport);
                    }
                }
            }
            String[] bar = new String[foo.Count];
            for (int i = 0; i < foo.Count; i++)
            {
                bar[i] = (String)(foo[i]);
            }
            return(bar);
        }
示例#5
0
 internal static void delPort(Session session)
 {
     lock (pool) {
         PortWatcher[] foo   = new PortWatcher[pool.Count];
         int           count = 0;
         for (int i = 0; i < pool.Count; i++)
         {
             PortWatcher p = (PortWatcher)(pool[i]);
             if (p.session == session)
             {
                 p.delete();
                 foo[count++] = p;
             }
         }
         for (int i = 0; i < count; i++)
         {
             PortWatcher p = foo[i];
             pool.Remove(p);
         }
     }
 }