The given argument may be "[bind_address:]port:host:hostport" or "[bind_address:]port host:hostport", which is from LocalForward command of ~/.ssh/config .
(String conf)
| 2023 | * ~/.ssh/config . |
| 2024 | */ |
| 2025 | private Forwarding parseForwarding(String conf) throws JSchException { |
| 2026 | String[] tmp = conf.split(" "); |
| 2027 | if(tmp.length>1){ // "[bind_address:]port host:hostport" |
| 2028 | Vector foo = new Vector(); |
| 2029 | for(int i=0; i<tmp.length; i++){ |
| 2030 | if(tmp[i].length()==0) continue; |
| 2031 | foo.addElement(tmp[i].trim()); |
| 2032 | } |
| 2033 | StringBuffer sb = new StringBuffer(); // join |
| 2034 | for(int i=0; i<foo.size(); i++){ |
| 2035 | sb.append((String)(foo.elementAt(i))); |
| 2036 | if(i+1<foo.size()) |
| 2037 | sb.append(":"); |
| 2038 | } |
| 2039 | conf = sb.toString(); |
| 2040 | } |
| 2041 | |
| 2042 | String org = conf; |
| 2043 | Forwarding f = new Forwarding(); |
| 2044 | try { |
| 2045 | if(conf.lastIndexOf(":") == -1) |
| 2046 | throw new JSchException ("parseForwarding: "+org); |
| 2047 | f.hostport = Integer.parseInt(conf.substring(conf.lastIndexOf(":")+1)); |
| 2048 | conf = conf.substring(0, conf.lastIndexOf(":")); |
| 2049 | if(conf.lastIndexOf(":") == -1) |
| 2050 | throw new JSchException ("parseForwarding: "+org); |
| 2051 | f.host = conf.substring(conf.lastIndexOf(":")+1); |
| 2052 | conf = conf.substring(0, conf.lastIndexOf(":")); |
| 2053 | if(conf.lastIndexOf(":") != -1){ |
| 2054 | f.port = Integer.parseInt(conf.substring(conf.lastIndexOf(":")+1)); |
| 2055 | conf = conf.substring(0, conf.lastIndexOf(":")); |
| 2056 | if(conf.length() ==0 || conf.equals("*")) conf="0.0.0.0"; |
| 2057 | if(conf.equals("localhost")) conf="127.0.0.1"; |
| 2058 | f.bind_address = conf; |
| 2059 | } |
| 2060 | else { |
| 2061 | f.port = Integer.parseInt(conf); |
| 2062 | f.bind_address = "127.0.0.1"; |
| 2063 | } |
| 2064 | } |
| 2065 | catch(NumberFormatException e){ |
| 2066 | throw new JSchException ("parseForwarding: "+e.toString()); |
| 2067 | } |
| 2068 | return f; |
| 2069 | } |
| 2070 | |
| 2071 | /** |
| 2072 | * Registers the local port forwarding. The argument should be |