SourceForge Jpcap

net.sourceforge.jpcap.net
Class MACAddress

java.lang.Object
  extended by net.sourceforge.jpcap.net.MACAddress

public class MACAddress
extends Object

MAC address.

This class encapsulates MAC addresses, and provides utility methods to extract a MAC address from a big-endian byte array or String.

Version:
$Revision: 1.1 $
Author:
Patrick Charles and Jonas Lehmann, EJP
Last modified by:
$Author: esmondpitt $
Last modified at:
$Date: 2008/08/21 02:58:27 $

Field Summary
static char SEPARATOR
          The separator character.
static int WIDTH
          The width in bytes of a MAC address.
 
Constructor Summary
MACAddress(byte[] address)
          Construct a new instance of MACAddress.
MACAddress(String address)
          Construct a new instance of MACAddress.
 
Method Summary
static String extract(int offset, byte[] bytes)
          Extract a MAC address from an array of bytes.
static byte[] extract(String address)
          Extract a MAC address from a String.
 byte[] getAddress()
          Return the MAC address as a byte[] array.
 String getAddressString()
          Fetch the MAC address as an unformatted string.
 String getMACAddress()
          Fetch the MAC address as formatted string.
static long random()
          Generate a random MAC address.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

WIDTH

public static final int WIDTH
The width in bytes of a MAC address.

See Also:
Constant Field Values

SEPARATOR

public static final char SEPARATOR
The separator character.

See Also:
Constant Field Values
Constructor Detail

MACAddress

public MACAddress(byte[] address)
Construct a new instance of MACAddress.

Parameters:
address - Address.
Since:
2.0.0

MACAddress

public MACAddress(String address)
Construct a new instance of MACAddress.

Parameters:
address - formatted Address, as per getMACAddress().
Since:
2.0.0
Method Detail

getAddress

public byte[] getAddress()
Return the MAC address as a byte[] array. To get the MAC address as a string, call toString().

Returns:
a byte array.
Since:
2.0.0
See Also:
getAddressString(), getMACAddress(), toString()

getAddressString

public String getAddressString()
Fetch the MAC address as an unformatted string.

Returns:
an unformatted string, to match NetworkInterface.
Since:
2.0.0

getMACAddress

public String getMACAddress()
Fetch the MAC address as formatted string.

Returns:
a formatted MAC address string, e.g. 00:11:22:33:44:55.
Since:
2.0.0

toString

public String toString()

This method returns the result of getMACAddress().

Overrides:
toString in class Object
Since:
2.0.0

extract

public static String extract(int offset,
                             byte[] bytes)
Extract a MAC address from an array of bytes.

Parameters:
offset - the offset of the address data from the start of the packet.
bytes - an array of bytes containing at least one MAC address.

extract

public static byte[] extract(String address)
Extract a MAC address from a String.

Parameters:
address - a MAC-address string as returned by extract(int, byte[])
Returns:
a byte array
Since:
2.0.0

random

public static long random()
Generate a random MAC address.


Copyright © Patrick Charles & Jonas Lehmann, 2001; Esmond Pitt, 2008.