Package org.apache.sshd.common.net
Class InetAddressRange
java.lang.Object
org.apache.sshd.common.net.InetAddressRange
Describes a range of IP addresses specified in CIDR notation.
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]Retrieves the broadcast address of this range as a MSB-first byte array.booleancontains(byte[] address) Tests whether this range contains the given IP address.booleancontains(InetAddress address) Tests whether this range contains the givenInetAddress.booleancontains(InetAddressRange other) Tests whether this range completely contains a given other range.booleanbyte[]first(boolean inclusive) Retrieves the first address of this range as a MSB-first byte array.static InetAddressRangeCreates anInetAddressRangefor a CIDR.inthashCode()static booleanTests whether a given string is a valid CIDR.booleanisIpV4()Tells whether this is an IPv4 address range.booleanisIpV6()Tells whether this is an IPv6 address range.byte[]last(boolean inclusive) Retrieves the last address of this range as a MSB-first byte array.intRetrieves the number of bits for the network zone.longnumberOfAddresses(boolean inclusive) Determines the number of IP addresses in the range.booleanoverlaps(InetAddressRange other) Tests whether this range overlaps a given other range.intRetrieves the number of bits for the subnet.toString()
-
Method Details
-
fromCIDR
Creates anInetAddressRangefor a CIDR.- Parameters:
cidr- the CIDR- Returns:
- an
InetAddressRange - Throws:
IllegalArgumentException- if thecidrcannot be parsed as a CIDR.
-
isCIDR
Tests whether a given string is a valid CIDR.- Parameters:
cidr- the string to test- Returns:
trueif the string can be parsed as a CIDR;falseotherwise
-
isIpV4
public boolean isIpV4()Tells whether this is an IPv4 address range.- Returns:
trueif this is an IPv4 address range,falseotherwise
-
isIpV6
public boolean isIpV6()Tells whether this is an IPv6 address range.- Returns:
trueif this is an IPv6 address range,falseotherwise
-
first
public byte[] first(boolean inclusive) Retrieves the first address of this range as a MSB-first byte array.If
subnetBits() <= 1, the address returned is always the zeroth address.- Parameters:
inclusive- whether to consider the zeroth address the first.- Returns:
- the first address of the range
-
last
public byte[] last(boolean inclusive) Retrieves the last address of this range as a MSB-first byte array.If
subnetBits() <= 1, the address returned is always thebroadcastAddress().- Parameters:
inclusive- whether to consider the direct broadcast address the last.- Returns:
- the last address of the range
-
broadcastAddress
public byte[] broadcastAddress()Retrieves the broadcast address of this range as a MSB-first byte array.- Returns:
- the broadcast address of the range
-
contains
Tests whether this range contains the givenInetAddress.- Parameters:
address-InetAddressto test- Returns:
trueif the address is in the range;falseotherwise
-
contains
public boolean contains(byte[] address) Tests whether this range contains the given IP address.- Parameters:
address- the IP address to test, as an MSB-first byte array- Returns:
trueif the address is in the range;falseotherwise
-
contains
Tests whether this range completely contains a given other range.- Parameters:
other-InetAddressRangeto test- Returns:
trueif the other range is completely contained in this range;falseotherwise
-
overlaps
Tests whether this range overlaps a given other range.- Parameters:
other-InetAddressRangeto test- Returns:
trueif this range overlaps with the other range;falseotherwise
-
networkZoneBits
public int networkZoneBits()Retrieves the number of bits for the network zone.- Returns:
- the number of bits for the network zone
-
subnetBits
public int subnetBits()Retrieves the number of bits for the subnet.- Returns:
- the number of bits for the subnet
-
numberOfAddresses
public long numberOfAddresses(boolean inclusive) Determines the number of IP addresses in the range.If
subnetBits() <= 1, the count always includes the first and last address.- Parameters:
inclusive- whether to include the first and last (broadcast) addresses in the count- Returns:
- the number of addresses in the subnet
-
hashCode
public int hashCode() -
equals
-
toString
-