fix: remove useless suffix of IPv6 address (#3189)

pull/3194/head
Steve Rao 2 years ago committed by GitHub
parent 6ead76d553
commit e50b3ae8a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -127,13 +127,16 @@ public class InetIPv6Util implements Closeable {
if (!StringUtils.isEmpty(ip)) {
int index = ip.indexOf('%');
ip = index > 0 ? ip.substring(0, index) : ip;
return iPv6Format(ip);
return normalizeIPv6(ip);
}
return ip;
}
public String iPv6Format(String ip) {
return "[" + ip + "]";
private String normalizeIPv6(String ip) {
// Remove the suffix of network card in IPv6 address, such as
// 2408:400a:8c:5400:6578:5c42:77b1:bc5d%eth0
int idx = ip.indexOf("%");
return idx != -1 ? "[" + ip.substring(0, idx) + "]" : "[" + ip + "]";
}
boolean isPreferredAddress(InetAddress address) {

Loading…
Cancel
Save