public class IpPrefix
extends java.lang.Object
NOTE: The stored IP address in the result IP prefix is masked to contain zeroes in all bits after the prefix length.
Modifier and Type | Field and Description |
---|---|
static IpPrefix |
IPV4_LINK_LOCAL_PREFIX
An IpPrefix that contains all IPv4 link local addresses.
|
static IpPrefix |
IPV4_MULTICAST_PREFIX
An IpPrefix that contains all IPv4 multicast addresses.
|
static IpPrefix |
IPV6_LINK_LOCAL_PREFIX
An IpPrefix that contains all IPv6 link local addresses.
|
static IpPrefix |
IPV6_MULTICAST_PREFIX
An IpPrefix that contains all IPv6 multicast addresses.
|
static int |
MAX_INET_MASK_LENGTH
Longest IPv4 network prefix.
|
static int |
MAX_INET6_MASK_LENGTH
Longest IPv6 network prefix.
|
static IpPrefix |
MULTICAST_RANGE
Deprecated.
|
Modifier | Constructor and Description |
---|---|
protected |
IpPrefix()
Default constructor for Kryo serialization.
|
protected |
IpPrefix(IpAddress address,
int prefixLength)
Constructor for given IP address, and a prefix length.
|
Modifier and Type | Method and Description |
---|---|
IpAddress |
address()
Returns the IP address value of the prefix.
|
boolean |
contains(IpAddress other)
Determines whether a given IP address is contained within this prefix.
|
boolean |
contains(IpPrefix other)
Determines whether a given IP prefix is contained within this prefix.
|
boolean |
equals(java.lang.Object obj) |
Ip4Prefix |
getIp4Prefix()
Gets the
Ip4Prefix view of the IP prefix. |
Ip6Prefix |
getIp6Prefix()
Gets the
Ip6Prefix view of the IP prefix. |
int |
hashCode() |
boolean |
isIp4()
Tests whether the IP version of this prefix is IPv4.
|
boolean |
isIp6()
Tests whether the IP version of this prefix is IPv6.
|
boolean |
isMulticast()
Check if this IP prefix is a multicast prefix.
|
int |
prefixLength()
Returns the IP address prefix length.
|
java.lang.String |
toString() |
static IpPrefix |
valueOf(int address,
int prefixLength)
Converts an integer and a prefix length into an IPv4 prefix.
|
static IpPrefix |
valueOf(IpAddress.Version version,
byte[] address,
int prefixLength)
Converts a byte array and a prefix length into an IP prefix.
|
static IpPrefix |
valueOf(IpAddress address,
int prefixLength)
Converts an IP address and a prefix length into an IP prefix.
|
static IpPrefix |
valueOf(java.lang.String address)
Converts a CIDR (slash) notation string (e.g., "10.1.0.0/16" or
"1111:2222::/64") into an IP prefix.
|
IpAddress.Version |
version()
Returns the IP version of the prefix.
|
public static final int MAX_INET_MASK_LENGTH
public static final int MAX_INET6_MASK_LENGTH
@Deprecated public static final IpPrefix MULTICAST_RANGE
public static final IpPrefix IPV4_MULTICAST_PREFIX
public static final IpPrefix IPV6_MULTICAST_PREFIX
public static final IpPrefix IPV4_LINK_LOCAL_PREFIX
public static final IpPrefix IPV6_LINK_LOCAL_PREFIX
protected IpPrefix(IpAddress address, int prefixLength)
address
- the IP addressprefixLength
- the prefix lengthjava.lang.IllegalArgumentException
- if the prefix length value is invalidprotected IpPrefix()
public IpAddress.Version version()
public boolean isIp4()
public boolean isIp6()
public boolean isMulticast()
public IpAddress address()
public int prefixLength()
public Ip4Prefix getIp4Prefix()
Ip4Prefix
view of the IP prefix.Ip4Prefix
view of the IP prefix if it is IPv4,
otherwise nullpublic Ip6Prefix getIp6Prefix()
Ip6Prefix
view of the IP prefix.Ip6Prefix
view of the IP prefix if it is IPv6,
otherwise nullpublic static IpPrefix valueOf(int address, int prefixLength)
address
- an integer representing the IPv4 addressprefixLength
- the prefix lengthjava.lang.IllegalArgumentException
- if the prefix length value is invalidpublic static IpPrefix valueOf(IpAddress.Version version, byte[] address, int prefixLength)
version
- the IP address versionaddress
- the IP address value stored in network byte orderprefixLength
- the prefix lengthjava.lang.IllegalArgumentException
- if the prefix length value is invalidpublic static IpPrefix valueOf(IpAddress address, int prefixLength)
address
- the IP addressprefixLength
- the prefix lengthjava.lang.IllegalArgumentException
- if the prefix length value is invalidpublic static IpPrefix valueOf(java.lang.String address)
address
- an IP prefix in string form (e.g. "10.1.0.0/16" or
"1111:2222::/64")java.lang.IllegalArgumentException
- if the arguments are invalidpublic boolean contains(IpPrefix other)
other
- the IP prefix to testpublic boolean contains(IpAddress other)
other
- the IP address to testpublic int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object