strip scope from returned address strings

This commit is contained in:
zzz
2013-05-12 15:23:02 +00:00
parent 1b38a6478b
commit 7318632db9

View File

@ -95,7 +95,7 @@ public abstract class Addresses {
haveIPv6 = true;
if (shouldInclude(allMyIps[i], includeSiteLocal,
includeLoopbackAndWildcard, includeIPv6))
rv.add(allMyIps[i].getHostAddress());
rv.add(stripScope(allMyIps[i].getHostAddress()));
}
}
} catch (UnknownHostException e) {}
@ -113,7 +113,7 @@ public abstract class Addresses {
haveIPv6 = true;
if (shouldInclude(addr, includeSiteLocal,
includeLoopbackAndWildcard, includeIPv6))
rv.add(addr.getHostAddress());
rv.add(stripScope(addr.getHostAddress()));
}
}
}
@ -128,6 +128,17 @@ public abstract class Addresses {
return rv;
}
/**
* Strip the trailing "%nn" from Inet6Address.getHostAddress()
* @since IPv6
*/
private static String stripScope(String ip) {
int pct = ip.indexOf("%");
if (pct > 0)
ip = ip.substring(0, pct);
return ip;
}
private static boolean shouldInclude(InetAddress ia, boolean includeSiteLocal,
boolean includeLoopbackAndWildcard, boolean includeIPv6) {
return