Android APIs
public final class

IpPrefix

extends Object
implements Parcelable
java.lang.Object
   ↳ android.net.IpPrefix

Class Overview

This class represents an IP prefix, i.e., a contiguous block of IP addresses aligned on a power of two boundary (also known as an "IP subnet"). A prefix is specified by two pieces of information:

  • A starting IP address (IPv4 or IPv6). This is the first IP address of the prefix.
  • A prefix length. This specifies the length of the prefix by specifing the number of bits in the IP address, starting from the most significant bit in network byte order, that are constant for all addresses in the prefix.
For example, the prefix 192.0.2.0/24 covers the 256 IPv4 addresses from 192.0.2.0 to 192.0.2.255, inclusive, and the prefix 2001:db8:1:2 covers the 2^64 IPv6 addresses from 2001:db8:1:2:: to 2001:db8:1:2:ffff:ffff:ffff:ffff, inclusive. Objects of this class are immutable.

Summary

[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final Creator<IpPrefix> CREATOR Implement the Parcelable interface.
Public Methods
int describeContents()
Implement the Parcelable interface.
boolean equals(Object obj)
Compares this IpPrefix object against the specified object in obj.
InetAddress getAddress()
Returns a copy of the first IP address in the prefix.
int getPrefixLength()
Returns the prefix length of this IpPrefix.
byte[] getRawAddress()
Returns a copy of the IP address bytes in network order (the highest order byte is the zeroth element).
int hashCode()
Gets the hashcode of the represented IP prefix.
String toString()
Returns a string representation of this IpPrefix.
void writeToParcel(Parcel dest, int flags)
Implement the Parcelable interface.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Fields

public static final Creator<IpPrefix> CREATOR

Added in API level 21

Implement the Parcelable interface.

Public Methods

public int describeContents ()

Added in API level 21

Implement the Parcelable interface.

Returns
  • a bitmask indicating the set of special object types marshalled by the Parcelable.

public boolean equals (Object obj)

Added in API level 21

Compares this IpPrefix object against the specified object in obj. Two objects are equal if they have the same startAddress and prefixLength.

Parameters
obj the object to be tested for equality.
Returns
  • true if both objects are equal, false otherwise.

public InetAddress getAddress ()

Added in API level 21

Returns a copy of the first IP address in the prefix. Modifying the returned object does not change this object's contents.

Returns
  • the address in the form of a byte array.

public int getPrefixLength ()

Added in API level 21

Returns the prefix length of this IpPrefix.

Returns
  • the prefix length.

public byte[] getRawAddress ()

Added in API level 21

Returns a copy of the IP address bytes in network order (the highest order byte is the zeroth element). Modifying the returned array does not change this object's contents.

Returns
  • the address in the form of a byte array.

public int hashCode ()

Added in API level 21

Gets the hashcode of the represented IP prefix.

Returns
  • the appropriate hashcode value.

public String toString ()

Added in API level 21

Returns a string representation of this IpPrefix.

Returns
  • a string such as "192.0.2.0/24" or "2001:db8:1:2::/64".

public void writeToParcel (Parcel dest, int flags)

Added in API level 21

Implement the Parcelable interface.

Parameters
dest The Parcel in which the object should be written.
flags Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.