diff options
author | Paul Jensen <pauljensen@google.com> | 2014-05-27 10:19:39 -0400 |
---|---|---|
committer | Paul Jensen <pauljensen@google.com> | 2014-05-29 19:17:06 +0000 |
commit | 8ef3401d2ae613ff0f14d75be860f5c833019494 (patch) | |
tree | 972ebe75d9cb1bd3a3a4e1cc2848dd46788410d3 /core | |
parent | f0db8b622b36ad33214579308a6caf804a4871d2 (diff) | |
download | frameworks_base-8ef3401d2ae613ff0f14d75be860f5c833019494.zip frameworks_base-8ef3401d2ae613ff0f14d75be860f5c833019494.tar.gz frameworks_base-8ef3401d2ae613ff0f14d75be860f5c833019494.tar.bz2 |
Adjust Network's SocketFactory to restrict host name resolution to that Network
bug: 13885501
Change-Id: Iab9a5a2e060fe261f4be9ba974c1a55fb6b9c98b
(cherry picked from commit 92064edf55ee11967d9cc7529125236ee8e469b2)
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/net/Network.java | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/core/java/android/net/Network.java b/core/java/android/net/Network.java index e489e05..64516e6 100644 --- a/core/java/android/net/Network.java +++ b/core/java/android/net/Network.java @@ -94,11 +94,26 @@ public class Network implements Parcelable { mNetId = netId; } + private void connectToHost(Socket socket, String host, int port) throws IOException { + // Lookup addresses only on this Network. + InetAddress[] hostAddresses = getAllByName(host); + // Try all but last address ignoring exceptions. + for (int i = 0; i < hostAddresses.length - 1; i++) { + try { + socket.connect(new InetSocketAddress(hostAddresses[i], port)); + return; + } catch (IOException e) { + } + } + // Try last address. Do throw exceptions. + socket.connect(new InetSocketAddress(hostAddresses[hostAddresses.length - 1], port)); + } + @Override public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException { Socket socket = createSocket(); socket.bind(new InetSocketAddress(localHost, localPort)); - socket.connect(new InetSocketAddress(host, port)); + connectToHost(socket, host, port); return socket; } @@ -121,7 +136,7 @@ public class Network implements Parcelable { @Override public Socket createSocket(String host, int port) throws IOException { Socket socket = createSocket(); - socket.connect(new InetSocketAddress(host, port)); + connectToHost(socket, host, port); return socket; } |