xorp

Mac Class Reference

IEEE standard 48-bit address. More...

#include <mac.hh>

List of all members.

Public Member Functions

 Mac ()
 Default constructor.
 Mac (const uint8_t *from_uint8)
 Constructor from a (uint8_t *) memory pointer.
 Mac (const char *from_cstring) throw (InvalidString)
 Constructor from a string.
 Mac (const struct ether_addr &from_ether_addr)
 Constructor from ether_addr structure.
 Mac (const struct sockaddr &from_sockaddr)
 Constructor from sockaddr structure.
size_t copy_out (uint8_t *to_uint8) const
 Copy the Mac raw address to specified memory location.
size_t copy_out (struct ether_addr &to_ether_addr) const
 Copy the Mac raw address to ether_addr structure.
size_t copy_out (struct sockaddr &to_sockaddr) const
 Copy the Mac raw address to sockaddr structure.
size_t copy_in (const uint8_t *from_uint8)
 Copy a raw Mac address from specified memory location into Mac container.
size_t copy_in (const struct ether_addr &from_ether_addr)
 Copy a raw Mac address from ether_addr structure into Mac container.
size_t copy_in (const struct sockaddr &from_sockaddr)
 Copy a raw Mac address from sockaddr structure into Mac container.
size_t copy_in (const char *from_cstring) throw (InvalidString)
 Copy a Mac address from a string.
bool operator< (const Mac &other) const
 Less-Than Operator.
bool operator== (const Mac &other) const
 Equality Operator.
bool operator!= (const Mac &other) const
 Not-Equal Operator.
string str () const
 Convert this address from binary form to presentation format.
const uint8_t * addr () const
 Get the raw value of this address.
bool is_zero () const
 Test if this address is numerically zero.
bool is_unicast () const
 Test if this address is a valid unicast address.
bool is_multicast () const
 Test if this address is a valid multicast address.

Static Public Member Functions

static size_t addr_bytelen ()
 Get the size of the raw Mac address (in octets).
static uint32_t addr_bitlen ()
 Get the size of the raw Mac address (in number of bits).
static const MacZERO ()
 Pre-defined Mac address constants.
static const MacALL_ONES ()
static const MacBROADCAST ()
static const MacSTP_MULTICAST ()
static const MacLLDP_MULTICAST ()
static const MacGMRP_MULTICAST ()
static const MacGVRP_MULTICAST ()

Static Public Attributes

static const uint32_t ADDR_BITLEN = 48
 Number of bits in address as a constant.
static const uint32_t ADDR_BYTELEN = ADDR_BITLEN / 8
 Number of bytes in address as a constant.
static const uint8_t MULTICAST_BIT = 0x1
 The multicast bit in the first octet of the address.

Private Attributes

uint8_t _addr [ADDR_BYTELEN]

Detailed Description

IEEE standard 48-bit address.


Constructor & Destructor Documentation

Mac::Mac ( const uint8_t *  from_uint8) [explicit]

Constructor from a (uint8_t *) memory pointer.

Parameters:
from_uint8the pointer to the memory to copy the address value from.
Mac::Mac ( const char *  from_cstring) throw (InvalidString)

Constructor from a string.

Parameters:
from_cstringC-style string of the form XX:XX:XX:XX:XX:XX where X represents a hex-digit.
Exceptions:
InvalidStringif string passed does not match expected format.
Mac::Mac ( const struct ether_addr from_ether_addr)

Constructor from ether_addr structure.

Parameters:
from_ether_addrthe ether_addr structure to construct the Mac address from.
Mac::Mac ( const struct sockaddr &  from_sockaddr)

Constructor from sockaddr structure.

Parameters:
from_sockaddrthe sockaddr structure to construct the Mac address from.

Member Function Documentation

const uint8_t* Mac::addr ( ) const [inline]

Get the raw value of this address.

Returns:
the value of this MAC address as a pointer to an array of unsigned bytes.
static uint32_t Mac::addr_bitlen ( ) [inline, static]

Get the size of the raw Mac address (in number of bits).

Returns:
the size of the raw Mac address (in number of bits).
static size_t Mac::addr_bytelen ( ) [inline, static]

Get the size of the raw Mac address (in octets).

Returns:
the size of the raw Mac address (in octets).
size_t Mac::copy_in ( const struct ether_addr from_ether_addr)

Copy a raw Mac address from ether_addr structure into Mac container.

Parameters:
from_ether_addrthe storage to copy the address from.
Returns:
the number of copied octets.
size_t Mac::copy_in ( const uint8_t *  from_uint8)

Copy a raw Mac address from specified memory location into Mac container.

Parameters:
from_uint8the memory address to copy the address from.
Returns:
the number of copied octets.
size_t Mac::copy_in ( const struct sockaddr &  from_sockaddr)

Copy a raw Mac address from sockaddr structure into Mac container.

Parameters:
from_sockaddrthe storage to copy the address from.
Returns:
the number of copied octets.
size_t Mac::copy_in ( const char *  from_cstring) throw (InvalidString)

Copy a Mac address from a string.

Parameters:
from_cstringC-style string of the form XX:XX:XX:XX:XX:XX where X represents a hex-digit.
Exceptions:
InvalidStringif string passed does not match expected format.
size_t Mac::copy_out ( struct ether_addr to_ether_addr) const

Copy the Mac raw address to ether_addr structure.

Parameters:
to_ether_addrthe storage to copy the address to.
Returns:
the number of copied octets.
size_t Mac::copy_out ( uint8_t *  to_uint8) const

Copy the Mac raw address to specified memory location.

Parameters:
to_uint8 the pointer to the memory to copy the address to.
Returns:
the number of copied octets.
size_t Mac::copy_out ( struct sockaddr &  to_sockaddr) const

Copy the Mac raw address to sockaddr structure.

Parameters:
to_sockaddrthe storage to copy the address to.
Returns:
the number of copied octets.
bool Mac::is_multicast ( ) const

Test if this address is a valid multicast address.

Returns:
true if the address is a valid multicast address.
bool Mac::is_unicast ( ) const

Test if this address is a valid unicast address.

Returns:
true if the address is a valid unicast address.
bool Mac::is_zero ( ) const [inline]

Test if this address is numerically zero.

Returns:
true if the address is numerically zero.
bool Mac::operator!= ( const Mac other) const

Not-Equal Operator.

Parameters:
otherthe right-hand operand to compare against.
Returns:
true if the left-hand operand is numerically not same as the right-hand operand.
bool Mac::operator< ( const Mac other) const

Less-Than Operator.

Parameters:
otherthe right-hand operand to compare against.
Returns:
true if the left-hand operand is numerically smaller than the right-hand operand.
bool Mac::operator== ( const Mac other) const

Equality Operator.

Parameters:
otherthe right-hand operand to compare against.
Returns:
true if the left-hand operand is numerically same as the right-hand operand.
string Mac::str ( ) const

Convert this address from binary form to presentation format.

Returns:
C++ string with the human-readable ASCII representation of the address.

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations