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

pull/3206/head
Steve Rao 2 years ago committed by GitHub
parent 48497c9e72
commit 1ffd329f4b
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)) { if (!StringUtils.isEmpty(ip)) {
int index = ip.indexOf('%'); int index = ip.indexOf('%');
ip = index > 0 ? ip.substring(0, index) : ip; ip = index > 0 ? ip.substring(0, index) : ip;
return iPv6Format(ip); return normalizeIPv6(ip);
} }
return ip; return ip;
} }
public String iPv6Format(String ip) { public String normalizeIPv6(String ip) {
return "[" + 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) { boolean isPreferredAddress(InetAddress address) {

Loading…
Cancel
Save