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."); } }
/* void dump(byte[] foo){ for(int i=0; i<foo.length; i++){ if((foo[i]&0xf0)==0)System.out.print("0"); System.out.print(Integer.toHexString(foo[i]&0xff)); if(i%16==15){System.out.println(""); continue;} if(i%2==1)System.out.print(" "); } } */ internal static SharpSSH.SharpSsh.java.String[] guess(byte[]I_S, byte[]I_C) { //System.out.println("guess: "); SharpSSH.SharpSsh.java.String[] guess=new SharpSSH.SharpSsh.java.String[PROPOSAL_MAX]; Buffer sb=new Buffer(I_S); sb.setOffSet(17); Buffer cb=new Buffer(I_C); cb.setOffSet(17); for(int i=0; i<PROPOSAL_MAX; i++) { byte[] sp=sb.getString(); // server proposal byte[] cp=cb.getString(); // client proposal //System.out.println("server-proposal: |"+new String(sp)+"|"); //System.out.println("client-proposal: |"+new String(cp)+"|"); int j=0; int k=0; //System.out.println(new String(cp)); //loop(using BREAK instead): while(j<cp.Length) { while(j<cp.Length && cp[j]!=',')j++; if(k==j) return null; String algorithm=Util.getString(cp, k, j-k); //System.out.println("algorithm: "+algorithm); int l=0; int m=0; while(l<sp.Length) { while(l<sp.Length && sp[l]!=',')l++; if(m==l) return null; //System.out.println(" "+new String(sp, m, l-m)); if(algorithm.Equals(Util.getString(sp, m, l-m))) { guess[i]=algorithm; //System.out.println(" "+algorithm); goto BREAK; } l++; m=l; } j++; k=j; } BREAK: if(j==0) { guess[i]=""; } else if(guess[i]==null) { //System.out.println(" fail"); return null; } } // for(int i=0; i<PROPOSAL_MAX; i++){ // System.out.println("guess: ["+guess[i]+"]"); // } return guess; }
internal static String[] getPortForwarding(Session session) { java.util.Vector foo=new java.util.Vector(); lock(pool) { for(int i=0; i<pool.size(); i++) { PortWatcher p=(PortWatcher)(pool.elementAt(i)); if(p.session==session) { foo.addElement(p.lport+":"+p.host+":"+p.rport); } } } String[] bar=new String[foo.size()]; for(int i=0; i<foo.size(); i++) { bar[i]=(String)(foo.elementAt(i)); } return bar; }
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; } }
internal static void delPort(Session session, String address, int lport) { PortWatcher pw=getPort(session, address, lport); if(pw==null) { throw new JSchException("PortForwardingL: local port "+address+":"+lport+" is not registered."); } pw.delete(); pool.removeElement(pw); }
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; }