Correctly handle the stripping of the zoneId / scopeId in all cases. See #267
This commit is contained in:
parent
2ecef07c4a
commit
ec409751e1
@ -18,7 +18,6 @@ package io.netty.util.internal;
|
|||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
|
|
||||||
public final class SocketUtil {
|
public final class SocketUtil {
|
||||||
|
|
||||||
@ -27,49 +26,40 @@ public final class SocketUtil {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes care of stripping the zone id from the {@link InetAddress} if its an {@link Inet6Address} and the java
|
* Takes care of stripping the zone id / scope Id from the {@link InetAddress} if its an {@link Inet6Address} and the java
|
||||||
* version is < 7. After that a new {@link InetSocketAddress} is created based on the old one. This is needed because of a bug that exists in java
|
* version is < 7. After that a new {@link InetSocketAddress} is created based on the old one. This is needed because of a bug that exists in java
|
||||||
* versions < 7.
|
* versions < 7.
|
||||||
*
|
*
|
||||||
* See https://github.com/netty/netty/issues/267
|
* See https://github.com/netty/netty/issues/267
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static InetSocketAddress stripZoneId(InetSocketAddress socketAddress) throws UnknownHostException {
|
public static InetSocketAddress stripZoneId(InetSocketAddress socketAddress) {
|
||||||
return new InetSocketAddress(stripZoneId(socketAddress.getAddress()), socketAddress.getPort());
|
// If we have a java version which is >= 7 we can just return the given
|
||||||
}
|
// InetSocketAddress as this bug only seems
|
||||||
|
// to exist in java 6 (and maybe also versions before)
|
||||||
/**
|
if (DetectionUtil.javaVersion() >= 7) {
|
||||||
* Takes care of stripping the zone id from the {@link InetAddress} if its an {@link Inet6Address} and the java
|
return socketAddress;
|
||||||
* version is < 7. This is needed because of a bug that exists in java versions < 7.
|
}
|
||||||
*
|
InetAddress address = socketAddress.getAddress();
|
||||||
* See https://github.com/netty/netty/issues/267
|
if (address instanceof Inet6Address) {
|
||||||
*
|
Inet6Address inet6Address = (Inet6Address) address;
|
||||||
*/
|
|
||||||
public static InetAddress stripZoneId(InetAddress address) throws UnknownHostException {
|
|
||||||
// If we have a java version which is >= 7 we can just return the given
|
|
||||||
// InetSocketAddress as this bug only seems
|
|
||||||
// to exist in java 6 (and maybe also versions before)
|
|
||||||
if (DetectionUtil.javaVersion() >= 7) {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (address instanceof Inet6Address) {
|
// Check if its a LinkLocalAddress as this is the only one which is
|
||||||
Inet6Address inet6Address = (Inet6Address) address;
|
// affected
|
||||||
|
if (inet6Address.isLinkLocalAddress()) {
|
||||||
|
String hostaddress = inet6Address.getHostAddress();
|
||||||
|
|
||||||
// Check if its a LinkLocalAddress as this is the only one which is
|
int separator = hostaddress.indexOf(ZONE_ID_SEPARATOR);
|
||||||
// affected
|
|
||||||
if (inet6Address.isLinkLocalAddress()) {
|
// check if the address contains a zoneId /scopeId and if so strip it
|
||||||
String hostaddress = inet6Address.getHostAddress();
|
if (separator != -1) {
|
||||||
|
// strip of the zoneId / scopeId
|
||||||
int separator = hostaddress.indexOf(ZONE_ID_SEPARATOR);
|
String withoutZonedId = inet6Address.getHostAddress().substring(0, separator);
|
||||||
|
return new InetSocketAddress(withoutZonedId, socketAddress.getPort());
|
||||||
// strip of the zoneId
|
|
||||||
String withoutZonedId = inet6Address.getHostAddress().substring(0, separator);
|
|
||||||
return InetAddress.getByName(withoutZonedId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return address;
|
}
|
||||||
|
return socketAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SocketUtil() {
|
private SocketUtil() {
|
||||||
|
Loading…
Reference in New Issue
Block a user