DO NOT MERGE Revert "Add android.net.IpPrefix#contains()"

This reverts commit b98afb001c.

Change-Id: I3c11ddd66d22ab2756201b489127f1643fedb429
This commit is contained in:
Kris Giesing
2015-04-20 13:22:18 -07:00
parent b98afb001c
commit c00a5049e6
4 changed files with 7 additions and 49 deletions

View File

@@ -169,21 +169,6 @@ public final class IpPrefix implements Parcelable {
return prefixLength;
}
/**
* Determines whether the prefix contains the specified address.
*
* @param address An {@link InetAddress} to test.
* @return {@code true} if the prefix covers the given address.
*/
public boolean contains(InetAddress address) {
byte[] addrBytes = (address == null) ? null : address.getAddress();
if (addrBytes == null || addrBytes.length != this.address.length) {
return false;
}
NetworkUtils.maskRawAddress(addrBytes, prefixLength);
return Arrays.equals(this.address, addrBytes);
}
/**
* Returns a string representation of this {@code IpPrefix}.
*

View File

@@ -367,7 +367,13 @@ public final class RouteInfo implements Parcelable {
* @return {@code true} if the destination and prefix length cover the given address.
*/
public boolean matches(InetAddress destination) {
return mDestination.contains(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);
}
/**

View File

@@ -29,10 +29,6 @@ import junit.framework.TestCase;
public class IpPrefixTest extends TestCase {
private static InetAddress Address(String addr) {
return InetAddress.parseNumericAddress(addr);
}
// Explicitly cast everything to byte because "error: possible loss of precision".
private static final byte[] IPV4_BYTES = { (byte) 192, (byte) 0, (byte) 2, (byte) 4};
private static final byte[] IPV6_BYTES = {
@@ -212,34 +208,6 @@ public class IpPrefixTest extends TestCase {
assertAreNotEqual(p1, p2);
}
@SmallTest
public void testContains() {
IpPrefix p = new IpPrefix("2001:db8:f00::ace:d00d/127");
assertTrue(p.contains(Address("2001:db8:f00::ace:d00c")));
assertTrue(p.contains(Address("2001:db8:f00::ace:d00d")));
assertFalse(p.contains(Address("2001:db8:f00::ace:d00e")));
assertFalse(p.contains(Address("2001:db8:f00::bad:d00d")));
assertFalse(p.contains(Address("2001:4868:4860::8888")));
assertFalse(p.contains(null));
assertFalse(p.contains(Address("8.8.8.8")));
p = new IpPrefix("192.0.2.0/23");
assertTrue(p.contains(Address("192.0.2.43")));
assertTrue(p.contains(Address("192.0.3.21")));
assertFalse(p.contains(Address("192.0.0.21")));
assertFalse(p.contains(Address("8.8.8.8")));
assertFalse(p.contains(Address("2001:4868:4860::8888")));
IpPrefix ipv6Default = new IpPrefix("::/0");
assertTrue(ipv6Default.contains(Address("2001:db8::f00")));
assertFalse(ipv6Default.contains(Address("192.0.2.1")));
IpPrefix ipv4Default = new IpPrefix("0.0.0.0/0");
assertTrue(ipv4Default.contains(Address("255.255.255.255")));
assertTrue(ipv4Default.contains(Address("192.0.2.1")));
assertFalse(ipv4Default.contains(Address("2001:db8::f00")));
}
@SmallTest
public void testHashCode() {
IpPrefix p;

View File

@@ -90,7 +90,6 @@ public class RouteInfoTest extends TestCase {
assertFalse(r.matches(Address("2001:db8:f00::ace:d00e")));
assertFalse(r.matches(Address("2001:db8:f00::bad:d00d")));
assertFalse(r.matches(Address("2001:4868:4860::8888")));
assertFalse(r.matches(Address("8.8.8.8")));
r = new PatchedRouteInfo(Prefix("192.0.2.0/23"), null, "wlan0");
assertTrue(r.matches(Address("192.0.2.43")));