Package org.jruby.ext.socket
Class SubnetUtils
java.lang.Object
org.jruby.ext.socket.SubnetUtils
A class that performs some subnet calculations given a network address and a subnet mask.
- Since:
- 2.0 Extracted from Apache Commons Net Project.
- See Also:
-
- "http://www.faqs.org/rfcs/rfc1519.html"
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classConvenience container for subnet summary information. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate static final Patternprivate intprivate static final Patternprivate booleanWhether the broadcast/network address are included in host countprivate static final Stringprivate static final intprivate intprivate intprivate static final String -
Constructor Summary
ConstructorsConstructorDescriptionSubnetUtils(String cidrNotation) Constructor that takes a CIDR-notation string, e.g.SubnetUtils(String address, String mask) Constructor that takes a dotted decimal address and a dotted decimal mask. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate Stringformat(int[] octets) final SubnetUtils.SubnetInfogetInfo()Return aSubnetUtils.SubnetInfoinstance that contains subnet-specific statisticsbooleanReturnstrueif the return value ofSubnetUtils.SubnetInfo.getAddressCount()includes the network address and broadcast addresses.private intmatchAddress(Matcher matcher) (package private) intpop(int x) private intrangeCheck(int value, int begin, int end) voidsetInclusiveHostCount(boolean inclusiveHostCount) Set totrueif you want the return value ofSubnetUtils.SubnetInfo.getAddressCount()to include the network and broadcast addresses.private int[]toArray(int val) private StringtoCidrNotation(String addr, String mask) private int
-
Field Details
-
IP_ADDRESS
- See Also:
-
SLASH_FORMAT
- See Also:
-
addressPattern
-
cidrPattern
-
NBITS
private static final int NBITS- See Also:
-
netmask
private int netmask -
address
private int address -
network
private int network -
broadcast
private int broadcast -
inclusiveHostCount
private boolean inclusiveHostCountWhether the broadcast/network address are included in host count
-
-
Constructor Details
-
SubnetUtils
Constructor that takes 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-3 decimal digits in range 1-32
-
SubnetUtils
Constructor that takes 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
-
isInclusiveHostCount
public boolean isInclusiveHostCount()Returnstrueif the return value ofSubnetUtils.SubnetInfo.getAddressCount()includes the network address and broadcast addresses.- Since:
- 2.2
-
setInclusiveHostCount
public void setInclusiveHostCount(boolean inclusiveHostCount) Set totrueif you want the return value ofSubnetUtils.SubnetInfo.getAddressCount()to include the network and broadcast addresses.- Parameters:
inclusiveHostCount-- Since:
- 2.2
-
getInfo
Return aSubnetUtils.SubnetInfoinstance that contains subnet-specific statistics- Returns:
- new instance
-
calculate
-
toInteger
-
matchAddress
-
toArray
private int[] toArray(int val) -
format
-
rangeCheck
private int rangeCheck(int value, int begin, int end) -
pop
int pop(int x) -
toCidrNotation
-