Class IPAddressHelper
java.lang.Object
eu.emi.security.authn.x509.helpers.proxy.IPAddressHelper
Helpers for IP addresses comparison.
Mostly the code from Tigran's ipmatcher library (GNU license).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
private static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static int
getCidrNetmask
(int size, byte[] netmask, int offset) private static int
getInt
(byte[] bytes, int offset) Returns the big-endianint
value whose byte representation is the 4 bytes ofbytes
staringoffset
.private static long
getLong
(byte[] bytes, int offset) Returns the big-endianlong
value whose byte representation is the 8 bytes ofbytes
staringoffset
.static boolean
isWithinAddressSpace
(byte[] ipBytes, byte[] ipAddressWithNetmask) Tests whether the ipAddress is within the address space defined by the ipAddressWithNetmask.
-
Field Details
-
IPv4_FULL_MASK
private static final int IPv4_FULL_MASK- See Also:
-
IPv6_FULL_MASK
private static final int IPv6_FULL_MASK- See Also:
-
IPv6_HALF_MASK
private static final int IPv6_HALF_MASK- See Also:
-
-
Constructor Details
-
IPAddressHelper
public IPAddressHelper()
-
-
Method Details
-
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-endianlong
value whose byte representation is the 8 bytes ofbytes
staringoffset
.- Parameters:
bytes
-offset
-- Returns:
- long value
-
getInt
private static int getInt(byte[] bytes, int offset) Returns the big-endianint
value whose byte representation is the 4 bytes ofbytes
staringoffset
.- Parameters:
bytes
-offset
-- Returns:
- int value
-
getCidrNetmask
private static int getCidrNetmask(int size, byte[] netmask, int offset)
-