Package ai.vespa.net

Class CidrBlock

java.lang.Object
ai.vespa.net.CidrBlock

public class CidrBlock extends Object
Represents a single IPv4 or IPv6 CIDR block.
Author:
valerijf
  • Constructor Details

    • CidrBlock

      public CidrBlock(InetAddress inetAddress)
      Creates a CIDR block that only contains the provided IP address (/32 if IPv4, /128 if IPv6)
    • CidrBlock

      public CidrBlock(InetAddress inetAddress, int prefixLength)
    • CidrBlock

      public CidrBlock(byte[] address, int prefixLength)
  • Method Details

    • getInetAddress

      public InetAddress getInetAddress()
      Returns:
      The first IP address in this CIDR block
    • prefixLength

      public int prefixLength()
      Returns:
      the number of bits in the network mask
    • isIpv6

      public boolean isIpv6()
    • contains

      public boolean contains(InetAddress address)
      Returns:
      true iff the address is in this CIDR network.
    • resize

      public CidrBlock resize(int newPrefixLength)
      Returns a copy of this resized to the given newPrefixLength
    • clearLeastSignificantBits

      public CidrBlock clearLeastSignificantBits(int bits)
    • clearHostIdentifier

      public CidrBlock clearHostIdentifier()
      Returns:
      a copy of this CIDR block with the host identifier bits cleared
    • getByte

      public int getByte(int byteOffset)
      Return the byte at the given offset. 0 refers to the most significant byte of the address.
    • setByte

      public CidrBlock setByte(int byteOffset, int n)
      Set the byte at the given offset to 'n'. 0 refers to the most significant byte of the address.
    • addByte

      public CidrBlock addByte(int byteOffset, int n)
      Add 'n' to the byte at the given offset, truncating overflow bits. 0 refers to the most significant byte of the address.
    • overlapsWith

      public boolean overlapsWith(CidrBlock other)
    • getDomainName

      public String getDomainName()
      Returns:
      the .arpa address for this CIDR block, does not include bit outside the prefix
    • iterableCidrs

      public Iterable<CidrBlock> iterableCidrs()
      Returns:
      iterable over all CIDR blocks of the same prefix size, from the current one and up
    • iterableIps

      public Iterable<InetAddress> iterableIps()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • asString

      public String asString()
    • fromString

      public static CidrBlock fromString(String cidr)