8216417: cleanup of IPv6 scope-id handling

Reviewed-by: alanb, chegar, dfuchs
This commit is contained in:
Michael McMahon 2019-06-13 09:10:51 +01:00
parent 04ea6ae9b3
commit 247a6a2ce4
23 changed files with 761 additions and 595 deletions

View file

@ -43,6 +43,7 @@ import sun.net.NetHooks;
import sun.net.PlatformSocketImpl;
import sun.net.ResourceManager;
import sun.net.ext.ExtendedSocketOptions;
import sun.net.util.IPAddressUtil;
import sun.net.util.SocketExceptions;
/**
@ -157,8 +158,12 @@ abstract class AbstractPlainSocketImpl extends SocketImpl implements PlatformSoc
boolean connected = false;
try {
InetAddress address = InetAddress.getByName(host);
this.port = port;
// recording this.address as supplied by caller before calling connect
this.address = address;
this.port = port;
if (address.isLinkLocalAddress()) {
address = IPAddressUtil.toScopedAddress(address);
}
connectToAddress(address, port, timeout);
connected = true;
@ -182,8 +187,12 @@ abstract class AbstractPlainSocketImpl extends SocketImpl implements PlatformSoc
* @param port the specified port
*/
protected void connect(InetAddress address, int port) throws IOException {
this.port = port;
// recording this.address as supplied by caller before calling connect
this.address = address;
this.port = port;
if (address.isLinkLocalAddress()) {
address = IPAddressUtil.toScopedAddress(address);
}
try {
connectToAddress(address, port, timeout);
@ -215,10 +224,14 @@ abstract class AbstractPlainSocketImpl extends SocketImpl implements PlatformSoc
InetSocketAddress addr = (InetSocketAddress) address;
if (addr.isUnresolved())
throw new UnknownHostException(addr.getHostName());
// recording this.address as supplied by caller before calling connect
InetAddress ia = addr.getAddress();
this.address = ia;
this.port = addr.getPort();
this.address = addr.getAddress();
connectToAddress(this.address, port, timeout);
if (ia.isLinkLocalAddress()) {
ia = IPAddressUtil.toScopedAddress(ia);
}
connectToAddress(ia, port, timeout);
connected = true;
} finally {
if (!connected) {
@ -546,6 +559,9 @@ abstract class AbstractPlainSocketImpl extends SocketImpl implements PlatformSoc
NetHooks.beforeTcpBind(fd, address, lport);
}
}
if (address.isLinkLocalAddress()) {
address = IPAddressUtil.toScopedAddress(address);
}
socketBind(address, lport);
isBound = true;
}