Package com.fasterxml.uuid
Class EthernetAddress
java.lang.Object
com.fasterxml.uuid.EthernetAddress
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<EthernetAddress>
public class EthernetAddress
extends Object
implements Serializable, Cloneable, Comparable<EthernetAddress>
EthernetAddress encapsulates the 6-byte MAC address defined in
IEEE 802.1 standard.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionEthernetAddress(byte[] addr) Binary constructor that constructs an instance given the 6 byte (48-bit) address.EthernetAddress(long addr) Another binary constructor; constructs an instance from the given long argument; the lowest 6 bytes contain the address.EthernetAddress(String addrStr) String constructor; given a 'standard' ethernet MAC address string (like '00:C0:F0:3D:5B:7C'), constructs an EthernetAddress instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected static RandomHelper method for accessing configured random number generatorbyte[]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...intcompareTo(EthernetAddress other) Method that compares this EthernetAddress to one passed in as argument.static EthernetAddressFactory 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.static EthernetAddressFactory 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.booleanstatic EthernetAddressA factory method that will try to determine the ethernet address of the network interface that connects to the default network gateway.static EthernetAddressFactory method that locates a network interface that has a suitable mac address (ethernet cards, and things that emulate one), and return that address.static EthernetAddressA factory method to return the ethernet address of a specified network interface.static EthernetAddressFactory method that locates a network interface that has a suitable mac address (ethernet cards, and things that emulate one), and return that address.inthashCode()booleanMethod 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).booleanMethod that can be used to check if this address refers to a multicast address.byte[]Synonym to 'asByteArray()'voidtoByteArray(byte[] array) voidtoByteArray(byte[] array, int pos) longtoLong()toString()Returns the canonical string representation of this ethernet address.static EthernetAddressvalueOf(byte[] addr) Constructs a new EthernetAddress given the byte array that contains binary representation of the address.static EthernetAddressvalueOf(int[] addr) Constructs a new EthernetAddress given the byte array that contains binary representation of the address.static EthernetAddressvalueOf(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.static EthernetAddressConstructs a new EthernetAddress given a string representation of the ethernet address.
-
Field Details
-
_rnd
We may need a random number generator, for creating dummy ethernet address if no real interface is found. -
_address
protected final long _address48-bit MAC address, stored in 6 lowest-significant bytes (in big endian notation)
-
-
Constructor Details
-
EthernetAddress
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).- Parameters:
addrStr- String representation of the ethernet address- Throws:
NumberFormatException
-
EthernetAddress
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).- Throws:
NumberFormatException
-
EthernetAddress
public EthernetAddress(long addr) Another binary constructor; constructs an instance from the given long argument; the lowest 6 bytes contain the address.- Parameters:
addr- long that contains the MAC address in 6 least significant bytes.
-
-
Method Details
-
clone
Default cloning behaviour (bitwise copy) is just fine... -
valueOf
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.- Parameters:
addr- Binary representation of the ethernet address- Throws:
NumberFormatException- if addr is invalid (less or more than 6 bytes in array)
-
valueOf
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.- Parameters:
addr- Binary representation of the ethernet address- Throws:
NumberFormatException- if addr is invalid (less or more than 6 ints in array)
-
valueOf
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.- Parameters:
addrStr- String representation of the ethernet address- Throws:
NumberFormatException- if addr representation is invalid
-
valueOf
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.- Parameters:
addr- Long int representation of the ethernet address
-
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.- Returns:
- Ethernet address of one of interfaces system has; not including local or loopback addresses; if one exists, null if no such interfaces are found.
-
fromInterface
A factory method to return the ethernet address of a specified network interface.- Since:
- 4.2
-
fromPreferredInterface
Factory method that locates a network interface that has a suitable mac address (ethernet cards, and things that emulate one), and return that address. It will first try to identify an egress interface, and failing that, it will select indeterminately from all non-loopback interfaces found. Method is meant for accessing an address needed to construct generator for time+location based UUID generation method.- Returns:
- Ethernet address of one of interfaces system has; not including local or loopback addresses; if one exists, null if no such interfaces are found.
- Since:
- 4.2
-
fromEgressInterface
A factory method that will try to determine the ethernet address of the network interface that connects to the default network gateway. To do this it will try to open a connection to one of the root DNS servers, or barring that, to address 1.1.1.1, or finally if that also fails then to IPv6 address "1::1". If a connection can be opened then the interface through which that connection is routed is determined to be the default egress interface, and the corresponding address of that interface will be returned. If all attempts are unsuccessful, null will be returned.- Since:
- 4.2
-
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 multicast address to avoid accidental collision with real manufacturer-assigned MAC addresses.Internally a
SecureRandominstance is used for generating random number to base address on. -
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 multicast address to avoid accidental collision with real manufacturer-assigned MAC addresses.Address is created using specified random number generator.
-
asByteArray
public byte[] 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)- Returns:
- 6 byte byte array that contains the binary representation
-
toByteArray
public byte[] toByteArray()Synonym to 'asByteArray()'- Returns:
- 6 byte byte array that contains the binary representation
-
toByteArray
public void toByteArray(byte[] array) -
toByteArray
public void toByteArray(byte[] array, int pos) -
toLong
public long toLong() -
isMulticastAddress
public boolean 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. -
isLocallyAdministeredAddress
public boolean 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. -
equals
-
hashCode
public int hashCode() -
compareTo
Method that compares this EthernetAddress to one passed in as argument. Comparison is done simply by comparing individual address bytes in the order.- Specified by:
compareToin interfaceComparable<EthernetAddress>- Returns:
- negative number if this EthernetAddress should be sorted before the parameter address if they are equal, os positive non-zero number if this address should be sorted after parameter
-
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). -
_randomNumberGenerator
Helper method for accessing configured random number generator
-