public final class MacAddress extends CacheableDataType implements Comparable<MacAddress>
All constructors for this class are private. Creating instances
of MacAddress
is done via the static methods on the class.
Instances of this class are immutable, making them inherently threadsafe.
This class overrides equals(java.lang.Object)
and hashCode()
so that instances
play nicely with the Collection classes.
This class implements the Comparable
interface to ensure that a
sorted list of addresses is presented in an intuitive order.
Modifier and Type | Class and Description |
---|---|
static class |
MacAddress.Format
Designates the different MAC address string formats available.
|
Modifier and Type | Field and Description |
---|---|
static MacAddress |
BROADCAST
The broadcast address, that is ff:ff:ff:ff:ff:ff.
|
static MacAddress |
HSDP_MULTICAST
The multicast destination address for discovery packets./
|
static MacAddress |
LINK_LOCAL_00
The link local address ending in 00, that is 01:80:c2:00:00:00.
|
static MacAddress |
LINK_LOCAL_03
The link local address ending in 03, that is 01:80:c2:00:00:03.
|
static MacAddress |
LINK_LOCAL_0E
The link local address ending in 0E, that is 01:80:c2:00:00:0e.
|
static int |
MAC_ADDR_SIZE
Number of bytes for a MAC address.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(MacAddress o)
Implements the Comparable interface, to return addresses in
natural order.
|
boolean |
equals(Object o) |
String |
getEthernetCompany()
Returns the ethernet company name that this MAC address is associated
with.
|
int |
hashCode() |
void |
intoBuffer(ByteBuffer b)
Writes the bytes that represent the MAC address directly into
ByteBuffer at the buffer's current position. |
boolean |
isBroadcast()
Returns true if this is the broadcast address (FF:FF:FF:FF:FF:FF).
|
boolean |
isLinkLocal()
Returns true if this is one of the "Link Local" addresses.
|
boolean |
isMulticast()
Returns true if this is a multicast address.
|
boolean |
isVrrpVmac()
Returns true if this is a VMAC used by VRRP.
|
static MacAddress |
mac(byte[] bytes)
Convenience method that simply delegates to
valueOf(byte[]) . |
static MacAddress |
mac(long encodedAddress)
Convenience method that simply delegates to
valueOf(long) . |
static MacAddress |
mac(String address)
Convenience method that simply delegates to
valueOf(String) . |
byte[] |
toByteArray()
Returns a newly allocated byte array containing bytes that represent
the MAC address.
|
String |
toFormattedString(MacAddress.Format fmt)
Returns a string representation of this MAC address, using the
specified
MacAddress.Format . |
String |
toFormattedString(MacAddress.Format fmt,
boolean toLowerCase)
Returns a string representation of this MAC address, using the
specified
MacAddress.Format . |
long |
toLong()
Returns the MAC address represented as a long.
|
String |
toString()
Returns a string representation of this MAC address
in "XX:XX:XX:XX:XX:XX" form.
|
static MacAddress |
valueFrom(ByteBuffer buffer)
Reads 6 bytes from the specified byte buffer and creates a MAC address
entity.
|
static MacAddress |
valueOf(byte[] bytes)
Returns an object that represents the value of the MAC address defined
by the specified address bytes.
|
static MacAddress |
valueOf(long encodedAddress)
Returns an object that represents the value of the MAC address encoded
by the specified long value.
|
static MacAddress |
valueOf(String address)
Returns an object that represents the value of the MAC address defined
by the specified string.
|
getRefQ, keyFromBytes
public static final int MAC_ADDR_SIZE
public static final MacAddress BROADCAST
public static final MacAddress LINK_LOCAL_0E
public static final MacAddress LINK_LOCAL_03
public static final MacAddress LINK_LOCAL_00
public static final MacAddress HSDP_MULTICAST
public String getEthernetCompany()
A value of "(Unknown)" will be returned if no known mapping exists.
public String toString()
This is the same result as invoking
macAddr.toFormattedString(MacAddress.Format.MULTI_COLON)
.
public String toFormattedString(MacAddress.Format fmt)
MacAddress.Format
.
fmt
- the format to usepublic String toFormattedString(MacAddress.Format fmt, boolean toLowerCase)
MacAddress.Format
.
fmt
- the format to usetoLowerCase
- if true, hex digits will be lowercasepublic boolean isBroadcast()
public boolean isMulticast()
public boolean isLinkLocal()
cf. Link Layer Discovery Protocol (LLDP)
public boolean isVrrpVmac()
public byte[] toByteArray()
public void intoBuffer(ByteBuffer b)
ByteBuffer
at the buffer's current position. Note that the
address bytes are in network byte order; that is, the highest order byte
of the address is at index 0.b
- the byte buffer to write intopublic long toLong()
This method is provided to support the encoding of MAC addresses as long values.
public int compareTo(MacAddress o)
compareTo
in interface Comparable<MacAddress>
o
- the other MAC addressComparable.compareTo(T)
public static MacAddress valueOf(byte[] bytes)
bytes
- the MAC address bytesNullPointerException
- if the parameter is nullIllegalArgumentException
- if bytes length is not 6public static MacAddress mac(byte[] bytes)
valueOf(byte[])
.bytes
- the MAC address bytesNullPointerException
- if the parameter is nullIllegalArgumentException
- if bytes length is not 6public static MacAddress valueOf(String address)
Acceptable input formats are:
address
- the string representation of the MAC addressNullPointerException
- if address is nullIllegalArgumentException
- if address is not an acceptable formatpublic static MacAddress mac(String address)
valueOf(String)
.address
- the string representation of the MAC addressNullPointerException
- if address is nullIllegalArgumentException
- if address is not an acceptable formatpublic static MacAddress valueOf(long encodedAddress)
encodedAddress
- the encoded MAC addressIllegalArgumentException
- if the specified long is not a valid
encodementpublic static MacAddress mac(long encodedAddress)
valueOf(long)
.encodedAddress
- the encoded MAC addressIllegalArgumentException
- if the specified long is not a valid
encodementpublic static MacAddress valueFrom(ByteBuffer buffer)
buffer
- byte buffer from which to read the bytesBufferUnderflowException
- if the buffer does not have 6 bytes
remainingCopyright © 2015. All Rights Reserved.