java.lang.Object
io.smallrye.common.net.CidrAddress
- All Implemented Interfaces:
Serializable,Comparable<CidrAddress>
A Classless Inter-Domain Routing address. This is the combination of an IP address and a netmask.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CidrAddressThe CIDR address representing all IPv4 addresses.static final CidrAddressThe CIDR address representing all IPv6 addresses. -
Method Summary
Modifier and TypeMethodDescriptionintcompareAddressBytesTo(byte[] otherBytes, int otherNetmaskBits, int scopeId) Compare the bytes of this address to the bytes in the given array.intcompareTo(CidrAddress other) static CidrAddresscreate(byte[] addressBytes, int netmaskBits) Create a new CIDR address.static CidrAddresscreate(InetAddress networkAddress, int netmaskBits) Create a new CIDR address.booleanequals(CidrAddress obj) Returnstrueif this address is equal to the given address, orfalseif it is not.booleanReturnstrueif this address is equal to the given object, orfalseif it is not.Get the broadcast address for this CIDR block.intGet the netmask bits.Get the network address.intGet the match address scope ID (if it is an IPv6 address).inthashCode()booleanmatches(byte[] bytes) Determine if this CIDR address matches the given address bytes.booleanmatches(byte[] bytes, int scopeId) Determine if this CIDR address matches the given address bytes.booleanmatches(CidrAddress address) Determine if this CIDR address matches the given CIDR address.booleanmatches(Inet4Address address) Determine if this CIDR address matches the given address.booleanmatches(Inet6Address address) Determine if this CIDR address matches the given address.booleanmatches(InetAddress address) Determine if this CIDR address matches the given address.toString()
-
Field Details
-
INET4_ANY_CIDR
The CIDR address representing all IPv4 addresses. -
INET6_ANY_CIDR
The CIDR address representing all IPv6 addresses.
-
-
Method Details
-
create
Create a new CIDR address.- Parameters:
networkAddress- the network address (must not benull)netmaskBits- the netmask bits (0-32 for IPv4, or 0-128 for IPv6)- Returns:
- the CIDR address (not
null)
-
create
Create a new CIDR address.- Parameters:
addressBytes- the network address bytes (must not benull, must be 4 bytes for IPv4 or 16 bytes for IPv6)netmaskBits- the netmask bits (0-32 for IPv4, or 0-128 for IPv6)- Returns:
- the CIDR address (not
null)
-
matches
Determine if this CIDR address matches the given address.- Parameters:
address- the address to test- Returns:
trueif the address matches,falseotherwise
-
matches
public boolean matches(byte[] bytes) Determine if this CIDR address matches the given address bytes.- Parameters:
bytes- the address bytes to test- Returns:
trueif the address bytes match,falseotherwise
-
matches
public boolean matches(byte[] bytes, int scopeId) Determine if this CIDR address matches the given address bytes.- Parameters:
bytes- the address bytes to testscopeId- the scope ID, or 0 to match no scope- Returns:
trueif the address bytes match,falseotherwise
-
matches
Determine if this CIDR address matches the given address.- Parameters:
address- the address to test- Returns:
trueif the address matches,falseotherwise
-
matches
Determine if this CIDR address matches the given address.- Parameters:
address- the address to test- Returns:
trueif the address matches,falseotherwise
-
matches
Determine if this CIDR address matches the given CIDR address. This will be true only when the given CIDR block is wholly enclosed by this one.- Parameters:
address- the address to test- Returns:
trueif the given block is enclosed by this one,falseotherwise
-
getNetworkAddress
Get the network address. The returned address has a resolved name consisting of the most compact valid string representation of the network of this CIDR address.- Returns:
- the network address (not
null)
-
getBroadcastAddress
Get the broadcast address for this CIDR block. If the block has no broadcast address (either because it is IPv6 or it is too small) thennullis returned.- Returns:
- the broadcast address for this CIDR block, or
nullif there is none
-
getNetmaskBits
public int getNetmaskBits()Get the netmask bits. This will be in the range 0-32 for IPv4 addresses, and 0-128 for IPv6 addresses.- Returns:
- the netmask bits
-
getScopeId
public int getScopeId()Get the match address scope ID (if it is an IPv6 address).- Returns:
- the scope ID, or 0 if there is none or the address is an IPv4 address
-
compareTo
- Specified by:
compareToin interfaceComparable<CidrAddress>
-
compareAddressBytesTo
public int compareAddressBytesTo(byte[] otherBytes, int otherNetmaskBits, int scopeId) Compare the bytes of this address to the bytes in the given array.- Parameters:
otherBytes- the bytes to compare to (must not benull)otherNetmaskBits- the netmask bits for the byte arrayscopeId- the IPv6 scope ID, if any, or else zero- Returns:
-1,0, or1if this address is less than, equal to, or greater than the given address
-
equals
Returnstrueif this address is equal to the given object, orfalseif it is not. -
equals
Returnstrueif this address is equal to the given address, orfalseif it is not.- Parameters:
obj- the other address- Returns:
trueif this address is equal to the given address, orfalseif it is not
-
hashCode
public int hashCode() -
toString
-