Package org.apache.mina.filter.util
Class SubnetUtils
java.lang.Object
org.apache.mina.filter.util.SubnetUtils
Performs subnet calculations given a network address and a subnet mask.
This class is extracted from Apache commons-net project
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classAllows an object to be the target of the "for-each loop" statement for a SubnetInfo.private static final classIterates over a SubnetInfo.final classContains subnet summary information. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate static final Patternprivate final intprivate static final Patternprivate booleanWhether the broadcast/network address are included in host countprivate static final Stringprivate static final intprivate final intprivate final intprivate static final Stringprivate static final String -
Constructor Summary
ConstructorsConstructorDescriptionSubnetUtils(String cidrNotation) Constructs an instance from a CIDR-notation string, e.g.SubnetUtils(String address, String mask) Constructs an instance from a dotted decimal address and a dotted decimal mask. -
Method Summary
Modifier and TypeMethodDescriptionprivate static Stringformat(int[] octets) Converts a 4-element array into dotted decimal format.final SubnetUtils.SubnetInfogetInfo()Gets aSubnetUtils.SubnetInfoinstance that contains subnet-specific statisticsgetNext()Gets the next subnet for this instance.Gets the previous subnet for this instance.booleanTests if the return value ofSubnetUtils.SubnetInfo.getAddressCount()includes the network and broadcast addresses.private static intmatchAddress(Matcher matcher) Extracts the components of a dotted decimal address and pack into an integer using a regex matchprivate static intrangeCheck(int value, int begin, int end) Checks integer boundaries.voidsetInclusiveHostCount(boolean inclusiveHostCount) Sets totrueif you want the return value ofSubnetUtils.SubnetInfo.getAddressCount()to include the network and broadcast addresses.private static int[]toArray4(int val) Converts a packed integer address into a 4-element arrayprivate static intConverts a dotted decimal format address to a packed integer format.toString()Converts this instance to a debug String.
-
Field Details
-
IP_ADDRESS
- See Also:
-
SLASH_FORMAT
- See Also:
-
ADDRESS_PATTERN
-
CIDR_PATTERN
-
NBITS
private static final int NBITS- See Also:
-
PARSE_FAIL
- See Also:
-
address
private final int address -
broadcast
private final int broadcast -
inclusiveHostCount
private boolean inclusiveHostCountWhether the broadcast/network address are included in host count -
netmask
private final int netmask -
network
private final int network
-
-
Constructor Details
-
SubnetUtils
Constructs an instance from a CIDR-notation string, e.g. "192.168.0.1/16"- Parameters:
cidrNotation- A CIDR-notation string, e.g. "192.168.0.1/16"- Throws:
IllegalArgumentException- if the parameter is invalid, i.e. does not match n.n.n.n/m where n=1-3 decimal digits, m = 1-2 decimal digits in range 0-32
-
SubnetUtils
Constructs an instance from a dotted decimal address and a dotted decimal mask.- Parameters:
address- An IP address, e.g. "192.168.0.1"mask- A dotted decimal netmask e.g. "255.255.0.0"- Throws:
IllegalArgumentException- if the address or mask is invalid, i.e. does not match n.n.n.n where n=1-3 decimal digits and the mask is not all zeros
-
-
Method Details
-
format
Converts a 4-element array into dotted decimal format. -
matchAddress
Extracts the components of a dotted decimal address and pack into an integer using a regex match -
rangeCheck
private static int rangeCheck(int value, int begin, int end) Checks integer boundaries. Checks if a value x is in the range [begin,end]. Returns x if it is in range, throws an exception otherwise. -
toArray4
private static int[] toArray4(int val) Converts a packed integer address into a 4-element array -
toInteger
Converts a dotted decimal format address to a packed integer format. -
getInfo
Gets aSubnetUtils.SubnetInfoinstance that contains subnet-specific statistics- Returns:
- new instance
-
getNext
Gets the next subnet for this instance.- Returns:
- the next subnet for this instance.
-
getPrevious
Gets the previous subnet for this instance.- Returns:
- the next previous for this instance.
-
isInclusiveHostCount
public boolean isInclusiveHostCount()Tests if the return value ofSubnetUtils.SubnetInfo.getAddressCount()includes the network and broadcast addresses.- Returns:
- true if the host count includes the network and broadcast addresses
- Since:
- 2.2
-
setInclusiveHostCount
public void setInclusiveHostCount(boolean inclusiveHostCount) Sets totrueif you want the return value ofSubnetUtils.SubnetInfo.getAddressCount()to include the network and broadcast addresses. This also applies toSubnetUtils.SubnetInfo.isInRange(int)- Parameters:
inclusiveHostCount- true if network and broadcast addresses are to be included- Since:
- 2.2
-
toString
Converts this instance to a debug String.
-