Class IPAddressHelper


  • public class IPAddressHelper
    extends java.lang.Object
    Helpers for IP addresses comparison. Mostly the code from Tigran's ipmatcher library (GNU license).
    • Constructor Summary

      Constructors 
      Constructor Description
      IPAddressHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static int getCidrNetmask​(int size, byte[] netmask, int offset)  
      private static int getInt​(byte[] bytes, int offset)
      Returns the big-endian int value whose byte representation is the 4 bytes of bytes staring offset.
      private static long getLong​(byte[] bytes, int offset)
      Returns the big-endian long value whose byte representation is the 8 bytes of bytes staring offset.
      static boolean isWithinAddressSpace​(byte[] ipBytes, byte[] ipAddressWithNetmask)
      Tests whether the ipAddress is within the address space defined by the ipAddressWithNetmask.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IPAddressHelper

        public IPAddressHelper()
    • Method Detail

      • isWithinAddressSpace

        public static boolean isWithinAddressSpace​(byte[] ipBytes,
                                                   byte[] ipAddressWithNetmask)
        Tests whether the ipAddress is within the address space defined by the ipAddressWithNetmask.
        Parameters:
        ipBytes - The IP address bytes to compare against the address space.
        ipAddressWithNetmask - The 8 (IPv4) or 32 (IPv6) byte array containing in the first half the base IP address bytes and in the second half the netmask bytes.
        Returns:
        true if ip matches subnet.
      • getLong

        private static long getLong​(byte[] bytes,
                                    int offset)
        Returns the big-endian long value whose byte representation is the 8 bytes of bytes staring offset.
        Parameters:
        bytes -
        offset -
        Returns:
        long value
      • getInt

        private static int getInt​(byte[] bytes,
                                  int offset)
        Returns the big-endian int value whose byte representation is the 4 bytes of bytes staring offset.
        Parameters:
        bytes -
        offset -
        Returns:
        int value
      • getCidrNetmask

        private static int getCidrNetmask​(int size,
                                          byte[] netmask,
                                          int offset)