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 = Dns.GetHostEntry(address).AddressList[0]; ss = (factory == null) ? new TcpListener(boundaddress, lport) : factory.createServerSocket(lport, 0, boundaddress); } catch (Exception e) { //Console.Error.WriteLine(e); string message = "PortForwardingL: local port " + address + ":" + lport + " cannot be bound."; throw new JSchException(message, e); } if (lport == 0) { int assigned = ((IPEndPoint)ss.LocalEndpoint).Port; if (assigned != -1) { this.lport = assigned; } } }
/// <exception cref="NSch.JSchException"></exception> 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 = Sharpen.Extensions.GetAddressByName(address); ss = (factory == null) ? Sharpen.Extensions.CreateServerSocket(lport, 0, boundaddress ) : factory.CreateServerSocket(lport, 0, boundaddress); } catch (Exception e) { //System.err.println(e); string message = "PortForwardingL: local port " + address + ":" + lport + " cannot be bound."; if (e is Exception) { throw new JSchException(message, (Exception)e); } throw new JSchException(message); } if (lport == 0) { int assigned = ss.GetLocalPort(); if (assigned != -1) { this.lport = assigned; } } }
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 = Dns.GetHostEntry(address).AddressList[0]; ss = (factory == null) ? new TcpListener(boundaddress,lport) : factory.createServerSocket(lport, 0, boundaddress); } catch (Exception e) { //Console.Error.WriteLine(e); string message = "PortForwardingL: local port " + address + ":" + lport + " cannot be bound."; throw new JSchException(message,e); } if (lport == 0) { int assigned = ((IPEndPoint)ss.LocalEndpoint).Port; if (assigned != -1) this.lport = assigned; } }
/// <exception cref="NSch.JSchException"></exception> internal static NSch.PortWatcher AddPort(Session session, string address, int lport , string host, int rport, ServerSocketFactory ssf) { if (GetPort(session, address, lport) != null) { throw new JSchException("PortForwardingL: local port " + address + ":" + lport + " is already registered."); } NSch.PortWatcher pw = new NSch.PortWatcher(session, address, lport, host, rport, ssf); pool.Add(pw); return(pw); }
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."); } }
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."); } }
public 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 { //Ignore microsoft's warning regarding "GetHostByName" being obsoleted. // //The proposed alternative, "GetHostEntry", is intended to be more generally correct (also handles IPV6), but // it actually does completely the WRONG thing when provided with a raw IPV4 address like "127.0.0.1": it should // use it as-is (at least that was the intention in this code), and instead it identifies the host and gets ALL // the most-specific IP addresses of the host ("localhost"), including IPV6 link-local addresses etc. So you say // "Bind to 127.0.0.1", and you get a listener that is actually bound to some link-local IPV6 address like // "fe80::84a:eaa6:244a:bde1%12" OR (if you filter out IPV6) "192.168.1.111", either way NOT binding to localhost! // // In other words, only change this if you really know what you're doing. // boundaddress = new InetAddress( Dns.GetHostEntry(address).AddressList[0]); // Dns.GetHostByName(address).AddressList[0]); ss = (factory == null) ? new TcpListener(boundaddress.addr, lport) : factory.createServerSocket(lport, 0, boundaddress); //In the move from custom "ServerSocket" class to standard "TcpListener", we lost the auto-start. ss.Start(); } catch (Exception e) { throw new JSchException("PortForwardingL: local port " + address + ":" + lport + " cannot be bound.", e); } }
internal static PortWatcher addPort(Session session, String address, int lport, String host, int rport, ServerSocketFactory ssf) { if(getPort(session, address, lport)!=null) { throw new JSchException("PortForwardingL: local port "+ address+":"+lport+" is already registered."); } PortWatcher pw=new PortWatcher(session, address, lport, host, rport, ssf); pool.addElement(pw); return pw; }
public void setPortForwardingL(String boundaddress, int lport, String host, int rport, ServerSocketFactory ssf) { PortWatcher pw=PortWatcher.addPort(this, boundaddress, lport, host, rport, ssf); Thread tmp=new Thread(pw); tmp.setName("PortWatcher Thread for "+host); tmp.start(); }
/// <exception cref="NSch.JSchException"></exception> public virtual int SetPortForwardingL(string boundaddress, int lport, string host , int rport, ServerSocketFactory ssf) { PortWatcher pw = PortWatcher.AddPort(this, boundaddress, lport, host, rport, ssf); Sharpen.Thread tmp = new Sharpen.Thread(pw); tmp.SetName("PortWatcher Thread for " + host); if (daemon_thread) { tmp.SetDaemon(daemon_thread); } tmp.Start(); return pw.lport; }
public int setPortForwardingL(string boundaddress, int lport, string host, int rport, ServerSocketFactory ssf) { PortWatcher pw = PortWatcher.addPort(this, boundaddress, lport, host, rport, ssf); Thread tmp = new Thread(pw.run); tmp.Name="PortWatcher Thread for " + host; if (daemon_thread) { tmp.IsBackground=daemon_thread; } tmp.Start(); return pw.lport; }
public void setPortForwardingL(String boundaddress, int lport, String host, int rport, ServerSocketFactory ssf) { PortWatcher pw=PortWatcher.addPort(this, boundaddress, lport, host, rport, ssf); System.Threading.Thread tmp = new System.Threading.Thread(pw.run); tmp.Name = "PortWatcher Thread for "+host; tmp.Start(); }