summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2014-12-08 14:55:08 +0000
committerNeil Fuller <nfuller@google.com>2014-12-08 15:28:30 +0000
commitb3a4dd8402e39a4d1209515adaf01f6b288fcea9 (patch)
tree537644f469fded3aa2a38edf1f53cd88f8f85c3d
parent9f274e11ee4da6d4e76fb87c77ddb84e951a2703 (diff)
downloadlibcore-b3a4dd8402e39a4d1209515adaf01f6b288fcea9.zip
libcore-b3a4dd8402e39a4d1209515adaf01f6b288fcea9.tar.gz
libcore-b3a4dd8402e39a4d1209515adaf01f6b288fcea9.tar.bz2
When connecting to a SOCKS proxy, use the resolved IP
Noticed while inspecting the code. In HttpURLConnection a similar change was made recently (commit 797fdc6cc6bf16372e9464f189b535148f944ce9). Previously if the Proxy was specified with a resolved InetSocketAddress (i.e. one with a specific IP address already determined) the hostname would still be used to work out an IP address to connect to. For host names with multiple IPs the host connected to could be a different one than the one specified. Now if the InetAddress has been resolved it will be used. In the case where the InetAddress is bad this may delay DNS / resolution errors to later in the connection process. It will, however, avoid the "connect to a different host" issue, and avoid a reverse DNS lookup here when the host is not yet known. Change-Id: I46df5c38942f2d356ba2fd4541e0269021fd6496
-rw-r--r--luni/src/main/java/java/net/PlainSocketImpl.java10
1 files changed, 3 insertions, 7 deletions
diff --git a/luni/src/main/java/java/net/PlainSocketImpl.java b/luni/src/main/java/java/net/PlainSocketImpl.java
index 4e5ba44..0c50f62 100644
--- a/luni/src/main/java/java/net/PlainSocketImpl.java
+++ b/luni/src/main/java/java/net/PlainSocketImpl.java
@@ -301,16 +301,12 @@ public class PlainSocketImpl extends SocketImpl {
* Gets the InetAddress of the SOCKS proxy server.
*/
private InetAddress socksGetServerAddress() throws UnknownHostException {
- String proxyName;
// get socks server address from proxy. It is unnecessary to check
// "socksProxyHost" property, since all proxy setting should be
// determined by ProxySelector.
- InetSocketAddress addr = (InetSocketAddress) proxy.address();
- proxyName = addr.getHostName();
- if (proxyName == null) {
- proxyName = addr.getAddress().getHostAddress();
- }
- return InetAddress.getByName(proxyName);
+ InetSocketAddress socketAddress = (InetSocketAddress) proxy.address();
+ InetAddress address = socketAddress.getAddress();
+ return (address != null) ? address : InetAddress.getByName(socketAddress.getHostName());
}
/**