Package org.jboss.netty.handler.ipfilter
Class CIDR
java.lang.Object
org.jboss.netty.handler.ipfilter.CIDR
- All Implemented Interfaces:
Comparable<CIDR>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected InetAddressThe base address of the CIDR notationprotected intThe mask used in the CIDR notation -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static InetAddressaddressStringToInet(String addr) Convert an IPv4 or IPv6 textual representation into an InetAddress.abstract booleancontains(InetAddress inetAddress) Compares the given InetAddress against the CIDR and returns true if the ip is in the subnet-ip-range and false if not.booleanabstract InetAddressstatic byte[]getIpV4FromIpV6(Inet6Address address) Compute a byte representation of IpV4 from a IpV6static byte[]getIpV6FromIpV4(Inet4Address address) Compute a byte representation of IpV6 from a IpV4intgetMask()private static intgetNetMask(String netMask) Get the Subnet's Netmask in Decimal format.
i.e.: getNetMask("255.255.255.0") returns the integer CIDR maskinthashCode()static CIDRCreate CIDR using the CIDR or normal Notation
i.e.: CIDR subnet = newCIDR ("10.10.10.0/24"); or CIDR subnet = newCIDR ("1fff:0:0a88:85a3:0:0:ac1f:8001/24"); or CIDR subnet = newCIDR ("10.10.10.0/255.255.255.0");static CIDRnewCIDR(InetAddress baseAddress, int cidrMask) Create CIDR using the CIDR Notationstatic CIDRnewCIDR(InetAddress baseAddress, String scidrMask) Create CIDR using the normal Notationprivate static inttoString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Comparable
compareTo
-
Field Details
-
baseAddress
The base address of the CIDR notation -
cidrMask
protected int cidrMaskThe mask used in the CIDR notation
-
-
Constructor Details
-
CIDR
public CIDR()
-
-
Method Details
-
newCIDR
Create CIDR using the CIDR Notation- Returns:
- the generated CIDR
- Throws:
UnknownHostException
-
newCIDR
Create CIDR using the normal Notation- Returns:
- the generated CIDR
- Throws:
UnknownHostException
-
newCIDR
Create CIDR using the CIDR or normal Notation
i.e.: CIDR subnet = newCIDR ("10.10.10.0/24"); or CIDR subnet = newCIDR ("1fff:0:0a88:85a3:0:0:ac1f:8001/24"); or CIDR subnet = newCIDR ("10.10.10.0/255.255.255.0");- Returns:
- the generated CIDR
- Throws:
UnknownHostException
-
getBaseAddress
- Returns:
- the baseAddress of the CIDR block.
-
getMask
public int getMask()- Returns:
- the Mask length.
-
toString
-
getEndAddress
- Returns:
- the end address of this block.
-
contains
Compares the given InetAddress against the CIDR and returns true if the ip is in the subnet-ip-range and false if not.- Returns:
- returns true if the given IP address is inside the currently set network.
-
equals
-
hashCode
public int hashCode() -
addressStringToInet
Convert an IPv4 or IPv6 textual representation into an InetAddress.- Returns:
- the created InetAddress
- Throws:
UnknownHostException
-
getNetMask
Get the Subnet's Netmask in Decimal format.
i.e.: getNetMask("255.255.255.0") returns the integer CIDR mask- Parameters:
netMask- a network mask- Returns:
- the integer CIDR mask
-
parseInt
- Parameters:
intstr- a string containing an integer.def- the default if the string does not contain a valid integer.- Returns:
- the inetAddress from the integer
-
getIpV4FromIpV6
Compute a byte representation of IpV4 from a IpV6- Returns:
- the byte representation
- Throws:
IllegalArgumentException- if the IpV6 cannot be mapped to IpV4
-
getIpV6FromIpV4
Compute a byte representation of IpV6 from a IpV4- Returns:
- the byte representation
- Throws:
IllegalArgumentException- if the IpV6 cannot be mapped to IpV4
-