diff --git a/pom.xml b/pom.xml index 57fc03d..153be78 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.github.ravn.jsocks jsocks - 0.0.1-SNAPSHOT + 0.0.2-SNAPSHOT SOCKS proxy Cloned from http://sourceforge.net/projects/jsocks/ @@ -50,4 +50,4 @@ - \ No newline at end of file + diff --git a/src/com/runjva/sourceforge/jsocks/protocol/ProxyServer.java b/src/com/runjva/sourceforge/jsocks/protocol/ProxyServer.java index 3a6b022..00a0b50 100644 --- a/src/com/runjva/sourceforge/jsocks/protocol/ProxyServer.java +++ b/src/com/runjva/sourceforge/jsocks/protocol/ProxyServer.java @@ -282,7 +282,9 @@ private void handleRequest(final ProxyMessage msg) throws IOException { if (msg.ip == null) { if (msg instanceof Socks5Message) { - msg.ip = InetAddress.getByName(msg.host); + + if (getProxy() == null || (getProxy() != null && getProxy().resolveAddrLocally())) + msg.ip = InetAddress.getByName(msg.host); } else { throw new SocksException(SocksProxyBase.SOCKS_FAILURE); } @@ -345,7 +347,10 @@ private void onConnect(final ProxyMessage msg) throws IOException { if (proxy == null) { s = new Socket(msg.ip, msg.port); } else { - s = new SocksSocket(proxy, msg.ip, msg.port); + if (proxy.resolveAddrLocally()) + s = new SocksSocket(proxy, msg.ip, msg.port); + else + s = new SocksSocket(proxy, msg.host, msg.port); } log.info("Connected to " + s.getInetAddress() + ":" + s.getPort()); @@ -372,7 +377,11 @@ private void onBind(final ProxyMessage msg) throws IOException { if (proxy == null) { ss = new ServerSocket(0); } else { - ss = new SocksServerSocket(proxy, msg.ip, msg.port); + if (proxy.resolveAddrLocally()) + ss = new SocksServerSocket(proxy, msg.ip, msg.port); + else + ss = new SocksServerSocket(proxy, msg.host, msg.port); + } ss.setSoTimeout(acceptTimeout); diff --git a/src/com/runjva/sourceforge/jsocks/protocol/Socks5Proxy.java b/src/com/runjva/sourceforge/jsocks/protocol/Socks5Proxy.java index 7400aa6..8422382 100644 --- a/src/com/runjva/sourceforge/jsocks/protocol/Socks5Proxy.java +++ b/src/com/runjva/sourceforge/jsocks/protocol/Socks5Proxy.java @@ -20,7 +20,6 @@ public class Socks5Proxy extends SocksProxyBase implements Cloneable { private Hashtable authMethods = new Hashtable(); private int selectedMethod; - boolean resolveAddrLocally = true; UDPEncapsulation udp_encapsulation = null; // Public Constructors @@ -92,32 +91,6 @@ public Socks5Proxy(InetAddress proxyIP, int proxyPort) { // Public instance methods // ======================== - /** - * Wether to resolve address locally or to let proxy do so. - *

- * SOCKS5 protocol allows to send host names rather then IPs in the - * requests, this option controls wether the hostnames should be send to the - * proxy server as names, or should they be resolved locally. - * - * @param doResolve - * Wether to perform resolution locally. - * @return Previous settings. - */ - public boolean resolveAddrLocally(boolean doResolve) { - final boolean old = resolveAddrLocally; - resolveAddrLocally = doResolve; - return old; - } - - /** - * Get current setting on how the addresses should be handled. - * - * @return Current setting for address resolution. - * @see Socks5Proxy#resolveAddrLocally(boolean doResolve) - */ - public boolean resolveAddrLocally() { - return resolveAddrLocally; - } /** * Adds another authentication method. diff --git a/src/com/runjva/sourceforge/jsocks/protocol/SocksProxyBase.java b/src/com/runjva/sourceforge/jsocks/protocol/SocksProxyBase.java index ebf4fdb..6313e55 100644 --- a/src/com/runjva/sourceforge/jsocks/protocol/SocksProxyBase.java +++ b/src/com/runjva/sourceforge/jsocks/protocol/SocksProxyBase.java @@ -34,6 +34,7 @@ public abstract class SocksProxyBase { // Protected static/class variables protected static SocksProxyBase defaultProxy = null; + boolean resolveAddrLocally = true; // Constructors // ==================== SocksProxyBase(SocksProxyBase chainProxy, String proxyHost, int proxyPort) @@ -159,6 +160,33 @@ public boolean isDirect(InetAddress host) { return directHosts.contains(host); } + /** + * Wether to resolve address locally or to let proxy do so. + *

+ * SOCKS5 protocol allows to send host names rather then IPs in the + * requests, this option controls wether the hostnames should be send to the + * proxy server as names, or should they be resolved locally. + * + * @param doResolve + * Wether to perform resolution locally. + * @return Previous settings. + */ + public boolean resolveAddrLocally(boolean doResolve) { + final boolean old = resolveAddrLocally; + resolveAddrLocally = doResolve; + return old; + } + + /** + * Get current setting on how the addresses should be handled. + * + * @return Current setting for address resolution. + * @see Socks5Proxy#resolveAddrLocally(boolean doResolve) + */ + public boolean resolveAddrLocally() { + return resolveAddrLocally; + } + /** * Set the proxy which should be used to connect to given proxy. *