public class LinkAddress extends Object implements Parcelable
LinkAddress
consists of:
2001:db8::1/64
or 192.0.2.1/24
).
The address must be unicast, as multicast addresses cannot be assigned to interfaces.
OsConstants.IFA_F_*
values representing properties
of the address (e.g., android.system.OsConstants.IFA_F_OPTIMISTIC
).
OsConstants.IFA_F_*
values; defines the scope in which
the address is unique (e.g.,
android.system.OsConstants.RT_SCOPE_LINK
or
android.system.OsConstants.RT_SCOPE_UNIVERSE
).
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static Parcelable.Creator<LinkAddress> |
CREATOR
Implement the Parcelable interface.
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
LinkAddress(InetAddress address,
int prefixLength)
Constructs a new
LinkAddress from an InetAddress and a prefix length. |
LinkAddress(InetAddress address,
int prefixLength,
int flags,
int scope)
Constructs a new
LinkAddress from an InetAddress and prefix length, with
the specified flags and scope. |
LinkAddress(InterfaceAddress interfaceAddress)
Constructs a new
LinkAddress from an InterfaceAddress . |
LinkAddress(String address)
Constructs a new
LinkAddress from a string such as "192.0.2.5/24" or
"2001:db8::1/64". |
LinkAddress(String address,
int flags,
int scope)
Constructs a new
LinkAddress from a string such as "192.0.2.5/24" or
"2001:db8::1/64", with the specified flags and scope. |
Modifier and Type | Method and Description |
---|---|
int |
describeContents()
Implement the Parcelable interface.
|
boolean |
equals(Object obj)
Compares this
LinkAddress instance against obj . |
InetAddress |
getAddress()
Returns the
InetAddress of this LinkAddress . |
int |
getFlags()
Returns the flags of this
LinkAddress . |
int |
getNetworkPrefixLength()
Returns the prefix length of this
LinkAddress . |
int |
getPrefixLength()
Returns the prefix length of this
LinkAddress . |
int |
getScope()
Returns the scope of this
LinkAddress . |
int |
hashCode()
Returns a hashcode for this address.
|
boolean |
isGlobalPreferred()
Returns true if this
LinkAddress is global scope and preferred. |
boolean |
isSameAddressAs(LinkAddress other)
Determines whether this
LinkAddress and the provided LinkAddress
represent the same address. |
String |
toString()
Returns a string representation of this address, such as "192.0.2.1/24" or "2001:db8::1/64".
|
void |
writeToParcel(Parcel dest,
int flags)
Implement the Parcelable interface.
|
public static final Parcelable.Creator<LinkAddress> CREATOR
public LinkAddress(InetAddress address, int prefixLength, int flags, int scope)
LinkAddress
from an InetAddress
and prefix length, with
the specified flags and scope. Flags and scope are not checked for validity.address
- The IP address.prefixLength
- The prefix length.flags
- A bitmask of IFA_F_*
values representing properties of the address.scope
- An integer defining the scope in which the address is unique (e.g.,
OsConstants#RT_SCOPE_LINK
or OsConstants#RT_SCOPE_SITE
).public LinkAddress(InetAddress address, int prefixLength)
LinkAddress
from an InetAddress
and a prefix length.
The flags are set to zero and the scope is determined from the address.address
- The IP address.prefixLength
- The prefix length.public LinkAddress(InterfaceAddress interfaceAddress)
LinkAddress
from an InterfaceAddress
.
The flags are set to zero and the scope is determined from the address.interfaceAddress
- The interface address.public LinkAddress(String address)
LinkAddress
from a string such as "192.0.2.5/24" or
"2001:db8::1/64". The flags are set to zero and the scope is determined from the address.string
- The string to parse.public LinkAddress(String address, int flags, int scope)
LinkAddress
from a string such as "192.0.2.5/24" or
"2001:db8::1/64", with the specified flags and scope.string
- The string to parse.flags
- The address flags.scope
- The address scope.public String toString()
public boolean equals(Object obj)
LinkAddress
instance against obj
. Two addresses are equal if
their address, prefix length, flags and scope are equal. Thus, for example, two addresses
that have the same address and prefix length are not equal if one of them is deprecated and
the other is not.equals
in class Object
obj
- the object to be tested for equality.true
if both objects are equal, false
otherwise.Object.hashCode()
,
HashMap
public int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public boolean isSameAddressAs(LinkAddress other)
LinkAddress
and the provided LinkAddress
represent the same address. Two LinkAddresses
represent the same address
if they have the same IP address and prefix length, even if their properties are
different.other
- the LinkAddress
to compare to.true
if both objects have the same address and prefix length, false
otherwise.public InetAddress getAddress()
InetAddress
of this LinkAddress
.public int getPrefixLength()
LinkAddress
.public int getNetworkPrefixLength()
LinkAddress
.
TODO: Delete all callers and remove in favour of getPrefixLength().public int getFlags()
LinkAddress
.public int getScope()
LinkAddress
.public boolean isGlobalPreferred()
LinkAddress
is global scope and preferred.public int describeContents()
describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public void writeToParcel(Parcel dest, int flags)
writeToParcel
in interface Parcelable
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.PARCELABLE_WRITE_RETURN_VALUE
.