diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2015-01-22 04:46:27 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-01-22 04:46:27 +0000 |
commit | e001a6e4b9f965c18750f66e7648cd103cca7b2a (patch) | |
tree | 8b67c843925cd72906f51476d622374a67ecf69b | |
parent | 71a87d6cdcea216c7760d88dea4ebf002994595b (diff) | |
parent | 26bb48032cdcc8d69484ff168389c34e1f873250 (diff) | |
download | libcore-e001a6e4b9f965c18750f66e7648cd103cca7b2a.zip libcore-e001a6e4b9f965c18750f66e7648cd103cca7b2a.tar.gz libcore-e001a6e4b9f965c18750f66e7648cd103cca7b2a.tar.bz2 |
am 26bb4803: Merge "Use the IPv6 instead of the IPv4 wildcard address in sockets."
* commit '26bb48032cdcc8d69484ff168389c34e1f873250':
Use the IPv6 instead of the IPv4 wildcard address in sockets.
6 files changed, 24 insertions, 23 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/DatagramSocketTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/DatagramSocketTest.java index e585b14..d9f3d91 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/DatagramSocketTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/DatagramSocketTest.java @@ -745,12 +745,13 @@ public class DatagramSocketTest extends junit.framework.TestCase { public void test_getLocalSocketAddress_ANY() throws Exception { DatagramSocket s = new DatagramSocket(0); - try { - assertTrue("ANY address not IPv6: " + s.getLocalSocketAddress(), - ((InetSocketAddress) s.getLocalSocketAddress()).getAddress() instanceof Inet6Address); - } finally { - s.close(); - } + assertEquals("ANY address not IPv6: " + s.getLocalSocketAddress(), + Inet6Address.ANY, s.getLocalAddress()); + s.close(); + s = new DatagramSocket(0, null); + assertEquals(Inet6Address.ANY, s.getLocalAddress()); + assertFalse(0 == s.getLocalPort()); + s.close(); } public void test_setReuseAddressZ() throws Exception { diff --git a/luni/src/main/java/java/net/DatagramSocket.java b/luni/src/main/java/java/net/DatagramSocket.java index 01d3bed..3195240 100644 --- a/luni/src/main/java/java/net/DatagramSocket.java +++ b/luni/src/main/java/java/net/DatagramSocket.java @@ -77,7 +77,7 @@ public class DatagramSocket implements Closeable { */ public DatagramSocket(int aPort) throws SocketException { checkPort(aPort); - createSocket(aPort, Inet4Address.ANY); + createSocket(aPort, Inet6Address.ANY); } /** @@ -94,7 +94,7 @@ public class DatagramSocket implements Closeable { */ public DatagramSocket(int aPort, InetAddress addr) throws SocketException { checkPort(aPort); - createSocket(aPort, (addr == null) ? Inet4Address.ANY : addr); + createSocket(aPort, (addr == null) ? Inet6Address.ANY : addr); } private void checkPort(int aPort) { @@ -443,7 +443,7 @@ public class DatagramSocket implements Closeable { private void ensureBound() throws SocketException { if (!isBound()) { - impl.bind(0, Inet4Address.ANY); + impl.bind(0, Inet6Address.ANY); isBound = true; } } @@ -467,7 +467,7 @@ public class DatagramSocket implements Closeable { InetAddress addr; if (localAddr == null) { localPort = 0; - addr = Inet4Address.ANY; + addr = Inet6Address.ANY; } else { if (!(localAddr instanceof InetSocketAddress)) { throw new IllegalArgumentException("Local address not an InetSocketAddress: " + diff --git a/luni/src/main/java/java/net/InetSocketAddress.java b/luni/src/main/java/java/net/InetSocketAddress.java index f12c399..1b3eabe 100644 --- a/luni/src/main/java/java/net/InetSocketAddress.java +++ b/luni/src/main/java/java/net/InetSocketAddress.java @@ -67,7 +67,7 @@ public class InetSocketAddress extends SocketAddress { if (port < 0 || port > 65535) { throw new IllegalArgumentException("port=" + port); } - this.addr = (address == null) ? Inet4Address.ANY : address; + this.addr = (address == null) ? Inet6Address.ANY : address; this.hostname = null; this.port = port; } diff --git a/luni/src/main/java/java/net/ServerSocket.java b/luni/src/main/java/java/net/ServerSocket.java index b1d59d5..a2cd9c6 100644 --- a/luni/src/main/java/java/net/ServerSocket.java +++ b/luni/src/main/java/java/net/ServerSocket.java @@ -72,7 +72,7 @@ public class ServerSocket implements Closeable { * @throws IOException if an error occurs while creating the socket. */ public ServerSocket(int port) throws IOException { - this(port, DEFAULT_BACKLOG, Inet4Address.ANY); + this(port, DEFAULT_BACKLOG, Inet6Address.ANY); } /** @@ -83,7 +83,7 @@ public class ServerSocket implements Closeable { * @throws IOException if an error occurs while creating the socket. */ public ServerSocket(int port, int backlog) throws IOException { - this(port, backlog, Inet4Address.ANY); + this(port, backlog, Inet6Address.ANY); } /** @@ -98,7 +98,7 @@ public class ServerSocket implements Closeable { checkListen(port); this.impl = factory != null ? factory.createSocketImpl() : new PlainServerSocketImpl(); - InetAddress addr = (localAddress == null) ? Inet4Address.ANY : localAddress; + InetAddress addr = (localAddress == null) ? Inet6Address.ANY : localAddress; synchronized (this) { impl.create(true); @@ -317,7 +317,7 @@ public class ServerSocket implements Closeable { InetAddress addr; int port; if (localAddr == null) { - addr = Inet4Address.ANY; + addr = Inet6Address.ANY; port = 0; } else { if (!(localAddr instanceof InetSocketAddress)) { diff --git a/luni/src/main/java/java/net/Socket.java b/luni/src/main/java/java/net/Socket.java index 737b01b..7ee6b05 100644 --- a/luni/src/main/java/java/net/Socket.java +++ b/luni/src/main/java/java/net/Socket.java @@ -41,7 +41,7 @@ public class Socket implements Closeable { private boolean isInputShutdown = false; private boolean isOutputShutdown = false; - private InetAddress localAddress = Inet4Address.ANY; + private InetAddress localAddress = Inet6Address.ANY; private final Object connectLock = new Object(); @@ -317,7 +317,7 @@ public class Socket implements Closeable { isConnected = false; // RI compatibility: the RI returns the any address (but the original local port) after // close. - localAddress = Inet4Address.ANY; + localAddress = Inet6Address.ANY; impl.close(); } @@ -332,7 +332,7 @@ public class Socket implements Closeable { isConnected = false; // RI compatibility: the RI returns the any address (but the original local port) after // close. - localAddress = Inet4Address.ANY; + localAddress = Inet6Address.ANY; impl.onClose(); } @@ -579,7 +579,7 @@ public class Socket implements Closeable { throw new IllegalArgumentException("Local port out of range: " + localPort); } - InetAddress addr = localAddress == null ? Inet4Address.ANY : localAddress; + InetAddress addr = localAddress == null ? Inet6Address.ANY : localAddress; synchronized (this) { impl.create(streaming); isCreated = true; @@ -774,7 +774,7 @@ public class Socket implements Closeable { InetAddress addr; if (localAddr == null) { port = 0; - addr = Inet4Address.ANY; + addr = Inet6Address.ANY; } else { if (!(localAddr instanceof InetSocketAddress)) { throw new IllegalArgumentException("Local address not an InetSocketAddress: " + @@ -877,7 +877,7 @@ public class Socket implements Closeable { // options on create // impl.create(true); if (!usingSocks()) { - impl.bind(Inet4Address.ANY, 0); + impl.bind(Inet6Address.ANY, 0); } isBound = true; } diff --git a/luni/src/test/java/libcore/java/net/InetSocketAddressTest.java b/luni/src/test/java/libcore/java/net/InetSocketAddressTest.java index ccd8b72..d97c48a 100644 --- a/luni/src/test/java/libcore/java/net/InetSocketAddressTest.java +++ b/luni/src/test/java/libcore/java/net/InetSocketAddressTest.java @@ -63,7 +63,7 @@ public class InetSocketAddressTest extends TestCase { } InetSocketAddress isa = new InetSocketAddress((InetAddress)null, 80); - assertEquals("0.0.0.0", isa.getHostName()); + assertEquals("::", isa.getHostName()); try { new InetSocketAddress(InetAddress.getByName("localhost"), 65536); @@ -80,7 +80,7 @@ public class InetSocketAddressTest extends TestCase { public void test_ConstructorI() { InetSocketAddress isa = new InetSocketAddress(65535); - assertEquals("0.0.0.0", isa.getHostName()); + assertEquals("::", isa.getHostName()); assertEquals(65535, isa.getPort()); try { |