Class Subnet

java.lang.Object
org.apache.mina.filter.firewall.Subnet

public class Subnet extends Object
A IP subnet using the CIDR notation. Currently, only IP version 4 address are supported.
  • Field Details

    • IP_MASK_V4

      private static final int IP_MASK_V4
      See Also:
    • IP_MASK_V6

      private static final long IP_MASK_V6
      See Also:
    • BYTE_MASK

      private static final int BYTE_MASK
      See Also:
    • subnet

      private InetAddress subnet
    • subnetInt

      private int subnetInt
      An int representation of a subnet for IPV4 addresses
    • subnetLong

      private long subnetLong
      An long representation of a subnet for IPV6 addresses
    • subnetMask

      private long subnetMask
    • suffix

      private int suffix
  • Constructor Details

    • Subnet

      public Subnet(InetAddress subnet, int mask)
      Creates a subnet from CIDR notation. For example, the subnet 192.168.0.0/24 would be created using the InetAddress 192.168.0.0 and the mask 24.
      Parameters:
      subnet - The InetAddress of the subnet
      mask - The mask
  • Method Details

    • toInt

      private int toInt(InetAddress inetAddress)
      Converts an IP address into an integer
    • toLong

      private long toLong(InetAddress inetAddress)
      Converts an IP address into a long
    • toSubnet

      private long toSubnet(InetAddress address)
      Converts an IP address to a subnet using the provided mask
      Parameters:
      address - The address to convert into a subnet
      Returns:
      The subnet as an integer
    • inSubnet

      public boolean inSubnet(InetAddress address)
      Checks if the InetAddress is within this subnet
      Parameters:
      address - The InetAddress to check
      Returns:
      True if the address is within this subnet, false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object
      See Also:
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object