public class EthernetAddress extends Object implements Serializable, Cloneable, Comparable<EthernetAddress>
Modifier and Type | Field and Description |
---|---|
protected long |
_address
48-bit MAC address, stored in 6 lowest-significant bytes (in
big endian notation)
|
protected static Random |
_rnd
We may need a random number generator, for creating dummy ethernet
address if no real interface is found.
|
Constructor and Description |
---|
EthernetAddress(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.
|
Modifier and Type | Method and Description |
---|---|
protected static Random |
_randomNumberGenerator()
Helper method for accessing configured random number generator
|
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)
|
Object |
clone()
Default cloning behaviour (bitwise copy) is just fine...
|
int |
compareTo(EthernetAddress other)
Method that compares this EthernetAddress to one passed in as
argument.
|
static EthernetAddress |
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.
|
static EthernetAddress |
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.
|
boolean |
equals(Object o) |
static EthernetAddress |
fromEgressInterface()
A factory method that will try to determine the ethernet address of
the network interface that connects to the default network gateway.
|
static EthernetAddress |
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.
|
static EthernetAddress |
fromInterface(NetworkInterface nint)
A factory method to return the ethernet address of a specified network interface.
|
static EthernetAddress |
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.
|
int |
hashCode() |
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).
|
boolean |
isMulticastAddress()
Method that can be used to check if this address refers
to a multicast address.
|
byte[] |
toByteArray()
Synonym to 'asByteArray()'
|
void |
toByteArray(byte[] array) |
void |
toByteArray(byte[] array,
int pos) |
long |
toLong() |
String |
toString()
Returns the canonical string representation of this ethernet address.
|
static EthernetAddress |
valueOf(byte[] addr)
Constructs a new EthernetAddress given the byte array that contains
binary representation of the address.
|
static EthernetAddress |
valueOf(int[] addr)
Constructs a new EthernetAddress given the byte array that contains
binary representation of the address.
|
static EthernetAddress |
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.
|
static EthernetAddress |
valueOf(String addrStr)
Constructs a new EthernetAddress given a string representation of
the ethernet address.
|
protected static Random _rnd
protected final long _address
public EthernetAddress(String addrStr) throws NumberFormatException
addrStr
- String representation of the ethernet addressNumberFormatException
public EthernetAddress(byte[] addr) throws NumberFormatException
NumberFormatException
public EthernetAddress(long addr)
addr
- long that contains the MAC address in 6 least significant
bytes.public Object clone()
public static EthernetAddress valueOf(byte[] addr) throws NumberFormatException
addr
- Binary representation of the ethernet addressNumberFormatException
- if addr is invalid (less or more than
6 bytes in array)public static EthernetAddress valueOf(int[] addr) throws NumberFormatException
addr
- Binary representation of the ethernet addressNumberFormatException
- if addr is invalid (less or more than
6 ints in array)public static EthernetAddress valueOf(String addrStr) throws NumberFormatException
addrStr
- String representation of the ethernet addressNumberFormatException
- if addr representation is invalidpublic static EthernetAddress valueOf(long addr)
addr
- Long int representation of the ethernet addresspublic static EthernetAddress fromInterface()
public static EthernetAddress fromInterface(NetworkInterface nint)
public static EthernetAddress fromPreferredInterface()
public static EthernetAddress fromEgressInterface()
public static EthernetAddress constructMulticastAddress()
Internally a SecureRandom
instance is used for generating
random number to base address on.
public static EthernetAddress constructMulticastAddress(Random rnd)
Address is created using specified random number generator.
public byte[] asByteArray()
public byte[] toByteArray()
public void toByteArray(byte[] array)
public void toByteArray(byte[] array, int pos)
public long toLong()
public boolean isMulticastAddress()
public boolean isLocallyAdministeredAddress()
public int compareTo(EthernetAddress other)
compareTo
in interface Comparable<EthernetAddress>
public String toString()
protected static Random _randomNumberGenerator()
Copyright © 2023 FasterXML.com. All rights reserved.