Top Description Inners Fields Constructors Methods
org.wildfly.common.net

public final Class CidrAddress

extends Object
implements Serializable, Comparable<CidrAddress>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable, java.io.Serializable
Static Imports
java.lang.Integer.signum, .Math.min

A Classless Inter-Domain Routing address. This is the combination of an IP address and a netmask.
Author
David M. Lloyd

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private Inet4Address
private final byte[]
private int
public static final CidrAddress
INET4_ANY_CIDR

The CIDR address representing all IPv4 addresses.

public static final CidrAddress
INET6_ANY_CIDR

The CIDR address representing all IPv6 addresses.

private final int
private final InetAddress
private static final long
private String

Constructor Summary

AccessConstructor and Description
private
CidrAddress(final InetAddress networkAddress, final int netmaskBits)

Method Summary

Modifier and TypeMethod and Description
private static boolean
bitsMatch(byte[] address, byte[] test, int bits)

public int
compareAddressBytesTo(final byte[] otherBytes, final int otherNetmaskBits, final int scopeId)

public int
compareTo(final CidrAddress
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
public static CidrAddress

Returns:

the CIDR address (not null)
create
(InetAddress
the network address (must not be null)
networkAddress
,
int
the netmask bits (0-32 for IPv4, or 0-128 for IPv6)
netmaskBits
)

Create a new CIDR address.

public static CidrAddress

Returns:

the CIDR address (not null)
create
(byte[]
the network address bytes (must not be null, must be 4 bytes for IPv4 or 16 bytes for IPv6)
addressBytes
,
int
the netmask bits (0-32 for IPv4, or 0-128 for IPv6)
netmaskBits
)

Create a new CIDR address.

pack-priv static CidrAddress
create(byte[] addressBytes, int netmaskBits, boolean clone)

public boolean
equals(final Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public boolean
equals(final CidrAddress obj)

public Inet4Address

Returns:

the broadcast address for this CIDR block, or null if there is none
getBroadcastAddress
()

Get the broadcast address for this CIDR block.

public int

Returns:

the netmask bits
getNetmaskBits
()

Get the netmask bits.

public InetAddress

Returns:

the network address (not null)
getNetworkAddress
()

Get the network address.

public int

Returns:

the scope ID, or 0 if there is none or the address is an IPv4 address
getScopeId
()

Get the match address scope ID (if it is an IPv6 address).

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
private static byte[]
maskBits0(byte[] address, int bits)

private static byte[]
maskBits1(byte[] address, int bits)

public boolean

Returns:

true if the address matches, false otherwise
matches
(InetAddress
the address to test
address
)

Determine if this CIDR address matches the given address.

public boolean

Returns:

true if the address bytes match, false otherwise
matches
(byte[]
the address bytes to test
bytes
)

Determine if this CIDR address matches the given address bytes.

public boolean

Returns:

true if the address bytes match, false otherwise
matches
(byte[]
the address bytes to test
bytes
,
int
the scope ID, or 0 to match no scope
scopeId
)

Determine if this CIDR address matches the given address bytes.

public boolean

Returns:

true if the address matches, false otherwise
matches
(Inet4Address
the address to test
address
)

Determine if this CIDR address matches the given address.

public boolean

Returns:

true if the address matches, false otherwise
matches
(Inet6Address
the address to test
address
)

Determine if this CIDR address matches the given address.

public boolean

Returns:

true if the given block is enclosed by this one, false otherwise
matches
(CidrAddress
the address to test
address
)

Determine if this CIDR address matches the given CIDR address.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
pack-priv Object
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

broadcastback to summary
private Inet4Address broadcast
cachedBytesback to summary
private final byte[] cachedBytes
hashCodeback to summary
private int hashCode
INET4_ANY_CIDRback to summary
public static final CidrAddress INET4_ANY_CIDR

The CIDR address representing all IPv4 addresses.

INET6_ANY_CIDRback to summary
public static final CidrAddress INET6_ANY_CIDR

The CIDR address representing all IPv6 addresses.

netmaskBitsback to summary
private final int netmaskBits
networkAddressback to summary
private final InetAddress networkAddress
serialVersionUIDback to summary
private static final long serialVersionUID
toStringback to summary
private String toString

Constructor Detail

CidrAddressback to summary
private CidrAddress(final InetAddress networkAddress, final int netmaskBits)

Method Detail

bitsMatchback to summary
private static boolean bitsMatch(byte[] address, byte[] test, int bits)
compareAddressBytesToback to summary
public int compareAddressBytesTo(final byte[] otherBytes, final int otherNetmaskBits, final int scopeId)
compareToback to summary
public int compareTo(final CidrAddress other)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
other:CidrAddress

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

createback to summary
public static CidrAddress create(InetAddress networkAddress, int netmaskBits)

Create a new CIDR address.

Parameters
networkAddress:InetAddress

the network address (must not be null)

netmaskBits:int

the netmask bits (0-32 for IPv4, or 0-128 for IPv6)

Returns:CidrAddress

the CIDR address (not null)

createback to summary
public static CidrAddress create(byte[] addressBytes, int netmaskBits)

Create a new CIDR address.

Parameters
addressBytes:byte[]

the network address bytes (must not be null, must be 4 bytes for IPv4 or 16 bytes for IPv6)

netmaskBits:int

the netmask bits (0-32 for IPv4, or 0-128 for IPv6)

Returns:CidrAddress

the CIDR address (not null)

createback to summary
pack-priv static CidrAddress create(byte[] addressBytes, int netmaskBits, boolean clone)
equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

equalsback to summary
public boolean equals(final CidrAddress obj)
getBroadcastAddressback to summary
public Inet4Address 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) then null is returned.

Returns:Inet4Address

the broadcast address for this CIDR block, or null if there is none

getNetmaskBitsback to summary
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:int

the netmask bits

getNetworkAddressback to summary
public InetAddress 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:InetAddress

the network address (not null)

getScopeIdback to summary
public int getScopeId()

Get the match address scope ID (if it is an IPv6 address).

Returns:int

the scope ID, or 0 if there is none or the address is an IPv4 address

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

maskBits0back to summary
private static byte[] maskBits0(byte[] address, int bits)
maskBits1back to summary
private static byte[] maskBits1(byte[] address, int bits)
matchesback to summary
public boolean matches(InetAddress address)

Determine if this CIDR address matches the given address.

Parameters
address:InetAddress

the address to test

Returns:boolean

true if the address matches, false otherwise

matchesback to summary
public boolean matches(byte[] bytes)

Determine if this CIDR address matches the given address bytes.

Parameters
bytes:byte[]

the address bytes to test

Returns:boolean

true if the address bytes match, false otherwise

matchesback to summary
public boolean matches(byte[] bytes, int scopeId)

Determine if this CIDR address matches the given address bytes.

Parameters
bytes:byte[]

the address bytes to test

scopeId:int

the scope ID, or 0 to match no scope

Returns:boolean

true if the address bytes match, false otherwise

matchesback to summary
public boolean matches(Inet4Address address)

Determine if this CIDR address matches the given address.

Parameters
address:Inet4Address

the address to test

Returns:boolean

true if the address matches, false otherwise

matchesback to summary
public boolean matches(Inet6Address address)

Determine if this CIDR address matches the given address.

Parameters
address:Inet6Address

the address to test

Returns:boolean

true if the address matches, false otherwise

matchesback to summary
public boolean matches(CidrAddress address)

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:CidrAddress

the address to test

Returns:boolean

true if the given block is enclosed by this one, false otherwise

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

writeReplaceback to summary
pack-priv Object writeReplace()
org.wildfly.common.net back to summary

pack-priv final Class CidrAddress.Ser

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
pack-priv final byte[]
b

pack-priv final int
m

private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
Ser(final byte[] b, final int m)

Method Summary

Modifier and TypeMethod and Description
pack-priv Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bback to summary
pack-priv final byte[] b
mback to summary
pack-priv final int m
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

Serback to summary
pack-priv Ser(final byte[] b, final int m)

Method Detail

readResolveback to summary
pack-priv Object readResolve()