Top Fields Constructors Methods
io.netty.util.internal

public final Class MacAddressUtil

extends Object
Class Inheritance
Imports
io.netty.util.NetUtil, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.net.InetAddress, .NetworkInterface, .SocketException, java.util.Arrays, .Enumeration, .LinkedHashMap, .Map, .Map.Entry

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final InternalLogger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static byte[]

Returns:

byte array containing a MAC. null if no MAC can be found.
bestAvailableMac
()

Obtains the best MAC address found on local network interfaces.

pack-priv static int

Returns:

positive - current is better, 0 - cannot tell from MAC addr, negative - candidate is better.
compareAddresses
(byte[] current, byte[] candidate)

private static int

Returns:

positive - current is better, 0 - cannot tell, negative - candidate is better
compareAddresses
(InetAddress current, InetAddress candidate)

public static byte[]
defaultMachineId()

Returns the result of bestAvailableMac() if non-null otherwise returns a random EUI-64 MAC address.

public static String

Returns:

hex formatted MAC address.
formatAddress
(byte[]
byte array of a MAC address.
addr
)

public static byte[]

Returns:

The byte representation of the MAC address.
parseMAC
(String
The string representation of the MAC address.
value
)

Parse a EUI-48, MAC-48, or EUI-64 MAC address from a String and return it as a byte[].

private static int
private static void
validateMacSeparator(char separator)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EUI48_MAC_ADDRESS_LENGTHback to summary
private static final int EUI48_MAC_ADDRESS_LENGTH
EUI64_MAC_ADDRESS_LENGTHback to summary
private static final int EUI64_MAC_ADDRESS_LENGTH
loggerback to summary
private static final InternalLogger logger

Constructor Detail

MacAddressUtilback to summary
private MacAddressUtil()

Method Detail

bestAvailableMacback to summary
public static byte[] bestAvailableMac()

Obtains the best MAC address found on local network interfaces. Generally speaking, an active network interface used on public networks is better than a local network interface.

Returns:byte[]

byte array containing a MAC. null if no MAC can be found.

compareAddressesback to summary
pack-priv static int compareAddresses(byte[] current, byte[] candidate)
Returns:int

positive - current is better, 0 - cannot tell from MAC addr, negative - candidate is better.

compareAddressesback to summary
private static int compareAddresses(InetAddress current, InetAddress candidate)
Returns:int

positive - current is better, 0 - cannot tell, negative - candidate is better

defaultMachineIdback to summary
public static byte[] defaultMachineId()

Returns the result of bestAvailableMac() if non-null otherwise returns a random EUI-64 MAC address.

formatAddressback to summary
public static String formatAddress(byte[] addr)
Parameters
addr:byte[]

byte array of a MAC address.

Returns:String

hex formatted MAC address.

parseMACback to summary
public static byte[] parseMAC(String value)

Parse a EUI-48, MAC-48, or EUI-64 MAC address from a String and return it as a byte[].

Parameters
value:String

The string representation of the MAC address.

Returns:byte[]

The byte representation of the MAC address.

scoreAddressback to summary
private static int scoreAddress(InetAddress addr)
validateMacSeparatorback to summary
private static void validateMacSeparator(char separator)