diff options
author | Erik Kline <ek@google.com> | 2015-04-14 09:58:38 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-04-14 09:58:38 +0000 |
commit | 172cf0243587db7baaa2502a04d403185ec50f7b (patch) | |
tree | 7db6d130a4b71b386ae717c51b3b6ee9e3f80ba3 /core/java/android/net | |
parent | 75f4b76638addc27f3297bb934e68741ecd27d32 (diff) | |
parent | 73e056d3931b419c2653eb7365fb72b50a9a36c3 (diff) | |
download | frameworks_base-172cf0243587db7baaa2502a04d403185ec50f7b.zip frameworks_base-172cf0243587db7baaa2502a04d403185ec50f7b.tar.gz frameworks_base-172cf0243587db7baaa2502a04d403185ec50f7b.tar.bz2 |
am 73e056d3: am 402f2501: am 3312c6b9: Merge "Add android.net.IpPrefix#contains()"
* commit '73e056d3931b419c2653eb7365fb72b50a9a36c3':
Add android.net.IpPrefix#contains()
Diffstat (limited to 'core/java/android/net')
-rw-r--r-- | core/java/android/net/IpPrefix.java | 15 | ||||
-rw-r--r-- | core/java/android/net/RouteInfo.java | 8 |
2 files changed, 16 insertions, 7 deletions
diff --git a/core/java/android/net/IpPrefix.java b/core/java/android/net/IpPrefix.java index b268986..6b4f2d5 100644 --- a/core/java/android/net/IpPrefix.java +++ b/core/java/android/net/IpPrefix.java @@ -170,6 +170,21 @@ public final class IpPrefix implements Parcelable { } /** + * 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}. * * @return a string such as {@code "192.0.2.0/24"} or {@code "2001:db8:1:2::/64"}. diff --git a/core/java/android/net/RouteInfo.java b/core/java/android/net/RouteInfo.java index cfd20a0..90a2460 100644 --- a/core/java/android/net/RouteInfo.java +++ b/core/java/android/net/RouteInfo.java @@ -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); } /** |