Add android.net.IpPrefix#contains()

This was originally to avoid RuntimeException in RouteInfo#matches():
    When an IPv6 prefix with a length greater than the max permitted
    for IPv4 is matched against an Inet4Address, the call to
    NetworkUtils throws RuntimeException.

Change-Id: I92e2bd19a4e7d656cf682fd27678da07e211850d
This commit is contained in:
Erik Kline 2015-04-13 15:33:34 +09:00
commit b98afb001c

View file

@ -367,13 +367,7 @@ public final class RouteInfo implements Parcelable {
* @return {@code true} if the destination and prefix length cover the given address.
*/
public boolean matches(InetAddress destination) {
if (destination == null) return false;
// match the route destination and destination with prefix length
InetAddress dstNet = NetworkUtils.getNetworkPart(destination,
mDestination.getPrefixLength());
return mDestination.getAddress().equals(dstNet);
return mDestination.contains(destination);
}
/**