EthernetAddress Class

Definition

EthernetAddress encapsulates the 6-byte MAC address defined in IEEE 802.1 standard.

public class EthernetAddress implements Serializable, Cloneable, Comparable<EthernetAddress>
Inheritance
java.lang.Object
EthernetAddress
Implements
java.io.Serializable java.lang.Cloneable java.lang.Comparable<EthernetAddress>

Inherited Members

java.lang.Object.clone() java.lang.Object.equals(java.lang.Object) java.lang.Object.finalize() java.lang.Object.getClass() java.lang.Object.hashCode() java.lang.Object.notify() java.lang.Object.notifyAll() java.lang.Object.toString() java.lang.Object.wait() java.lang.Object.wait(long) java.lang.Object.wait(long,int)

Constructors

EthernetAddress(byte[] addr)

Binary constructor that constructs an instance given the 6 byte (48-bit) address. Useful if an address is saved in binary format (for saving space for example).

EthernetAddress(String addrStr)

String constructor; given a 'standard' ethernet MAC address string (like '00:C0:F0:3D:5B:7C'), constructs an EthernetAddress instance. Note that string is case-insensitive, and also that leading zeroes may be omitted. Thus '00:C0:F0:3D:5B:7C' and '0:c0:f0:3d:5b:7c' are equivalent, and a 'null' address could be passed as ':::::' as well as '00:00:00:00:00:00' (or any other intermediate combination).

EthernetAddress(long addr)

Another binary constructor; constructs an instance from the given long argument; the lowest 6 bytes contain the address.

Fields

_address

48-bit MAC address, stored in 6 lowest-significant bytes (in big endian notation)

_rnd

We may need a random number generator, for creating dummy ethernet address if no real interface is found.

Methods

_randomNumberGenerator()

Helper method for accessing configured random number generator

asByteArray()

Returns 6 byte byte array that contains the binary representation of this ethernet address; byte 0 is the most significant byte (and so forth)

clone()

Default cloning behaviour (bitwise copy) is just fine...

compareTo(EthernetAddress other)

Method that compares this EthernetAddress to one passed in as argument. Comparison is done simply by comparing individual address bytes in the order.

constructMulticastAddress()

Factory method that can be used to construct a random multicast address; to be used in cases where there is no "real" ethernet address to use. Address to generate should be a multicase address to avoid accidental collision with real manufacturer-assigned MAC addresses.

Internally a SecureRandom instance is used for generating random number to base address on.

constructMulticastAddress(Random rnd)

Factory method that can be used to construct a random multicast address; to be used in cases where there is no "real" ethernet address to use. Address to generate should be a multicase address to avoid accidental collision with real manufacturer-assigned MAC addresses.

Address is created using specified random number generator.

equals(Object o)
fromInterface()

Factory method that locates a network interface that has a suitable mac address (ethernet cards, and things that emulate one), and return that address. If there are multiple applicable interfaces, one of them is returned; which one is returned is not specified. Method is meant for accessing an address needed to construct generator for time+location based UUID generation method.

hashCode()
isLocallyAdministeredAddress()

Method that can be used to check if this address refers to a "locally administered address" (see [http://en.wikipedia.org/wiki/MAC_address] for details). Such addresses are not assigned to individual network cards.

isMulticastAddress()

Method that can be used to check if this address refers to a multicast address. Such addresses are never assigned to individual network cards.

toByteArray()

Synonym to 'asByteArray()'

toByteArray(byte[] array)
toByteArray(byte[] array, int pos)
toLong()
toString()

Returns the canonical string representation of this ethernet address. Canonical means that all characters are lower-case and string length is always 17 characters (ie. leading zeroes are not omitted).

valueOf(byte[] addr)

Constructs a new EthernetAddress given the byte array that contains binary representation of the address. Note that calling this method returns the same result as would using the matching constructor.

valueOf(int[] addr)

Constructs a new EthernetAddress given the byte array that contains binary representation of the address. Note that calling this method returns the same result as would using the matching constructor.

valueOf(String addrStr)

Constructs a new EthernetAddress given a string representation of the ethernet address. Note that calling this method returns the same result as would using the matching constructor.

valueOf(long addr)

Constructs a new EthernetAddress given the long int value (64-bit) representation of the ethernet address (of which 48 LSB contain the definition) Note that calling this method returns the same result as would using the matching constructor.

Applies to