Ethernet MAC address. More...

#include <senf/Socket/Protocols/Raw/MACAddress.hh>

Inheritance diagram for senf::MACAddress:

Public Member Functions

 MACAddress ()
 Construct zero-initialized address. More...
 
 MACAddress (senf::NoInit_t)
 Construct uninitialized (!) address. More...
 
 MACAddress (std::uint64_t const &v)
 Construct MACAddress constants. More...
 
 operator bool () const
 true, if address is not the zero address More...
 
bool operator< (MACAddress const &other) const
 
bool operator== (EUI64 const &eui64) const
 
bool local () const
 true, if address is locally administered More...
 
bool multicast () const
 true, if address is a group/multicast address More...
 
bool broadcast () const
 true, if address is the broadcast address More...
 
void local (bool flag)
 
void multicast (bool flag)
 
std::uint32_t oui () const
 Return first 3 bytes of the address. More...
 
std::uint32_t nic () const
 Return last 3 bytes of the address. More...
 
void oui (std::uint32_t oui)
 Sets first 3 bytes of the address. More...
 
void nic (std::uint32_t oui)
 Sets last 3 bytes of the address. More...
 
std::uint64_t eui64 () const
 Build EUI-64 from the MAC address. More...
 
std::uint64_t uint64 () const
 Return MAC address as uint64 value. More...
 
std::uint32_t const & hash32 () const
 
void hash (std::uint64_t *hash, std::uint16_t const &otherKey=0) const
 computes a fast uint64 hash mixing in another 16bit value More...
 

Static Public Member Functions

static MACAddress from_string (std::string const &s)
 Construct address from string representation. More...
 
template<class InputIterator >
static MACAddress from_data (InputIterator i)
 Construct address from raw data. More...
 
static MACAddress from_eui64 (senf::EUI64 const &eui)
 Construct address from EUI-64. More...
 

Static Public Attributes

static MACAddress const Broadcast = senf::MACAddress(0xFFFFFFFFFFFFull)
 The broadcast address. More...
 
static MACAddress const None
 The empty (0) address. More...
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &os, MACAddress const &mac)
 Output MAC instance as it's string representation. More...
 
std::istream & operator>> (std::istream &is, MACAddress &mac)
 Try to initialize MACAddress instance from a string representation sets std::ios::failbit on the stream if an error occurred. More...
 

Detailed Description

Ethernet MAC address.

The Ethernet MAC is modeled as a fixed-size container/sequence of 6 bytes. A MACAddress can be converted from/to the following representations

std::uint64_t senf::MACAddress(0x112233445566ull)
mac.uint64()
std::string senf::MACAddress::from_string("11:22:33:44:55:66")
senf::str(mac)
raw data
    (6 bytes)
senf::MACAddress::from_data(iterator)
mac.begin()
senf::EUI64 senf::MACAddress::from_eui64(eui64)
senf::EUI64::from_mac(mac)

Since MACAddress is based on boost::array, you can access the raw data bytes of the address using begin(), end() or operator[]:

std::vector<char> data;
data.resize(6);
std::copy(mac.begin(), mac.end(), data.begin()); // Copy 6 bytes
    \par "Implementation note:" We awkwardly need to use static named constructors (<tt>from_</tt> members)
        instead of ordinarily overloaded constructors for one simple reason: <tt>char *</tt>
        doubles as string literal and as arbitrary data iterator. The iterator constructor can
        therefore not be distinguished from initialization with a string literal. Therefore we
        need to disambiguate using the named constructors.

Definition at line 72 of file MACAddress.hh.

Constructor & Destructor Documentation

◆ MACAddress() [1/3]

senf::MACAddress::MACAddress ( )

Construct zero-initialized address.

◆ MACAddress() [2/3]

senf::MACAddress::MACAddress ( senf::NoInit_t  )

Construct uninitialized (!) address.

◆ MACAddress() [3/3]

senf::MACAddress::MACAddress ( std::uint64_t const &  v)
explicit

Construct MACAddress constants.

Member Function Documentation

◆ broadcast()

bool senf::MACAddress::broadcast ( ) const

true, if address is the broadcast address

◆ eui64()

std::uint64_t senf::MACAddress::eui64 ( ) const

Build EUI-64 from the MAC address.

◆ from_data()

template<class InputIterator >
static MACAddress senf::MACAddress::from_data ( InputIterator  i)
static

Construct address from raw data.

Copies the data from i into the MAC address.

Precondition
The input range at i must have a size of at least 6 elements.

◆ from_eui64()

senf::MACAddress senf::MACAddress::from_eui64 ( senf::EUI64 const &  eui)
static

Construct address from EUI-64.

This constructor takes an EUI-64 value and converts it to a MAC address. This conversion is only possible, if the EUI-64 is MAC compatible: the 4th/5th byte (in transmission order) must be 0xFFFE.

Exceptions
AddressSyntaxExceptionif eui is not a MAC compatible EUI-64.

Definition at line 41 of file MACAddress.cc.

◆ from_string()

senf::MACAddress senf::MACAddress::from_string ( std::string const &  s)
static

Construct address from string representation.

The string representation must exactly match the form dd:dd:dd:dd:dd:dd where d is any hexadecimal digit. In place of ':', '-' is also accepted as a delimiter.

Exceptions
AddressSyntaxException

Definition at line 34 of file MACAddress.cc.

◆ hash()

void senf::MACAddress::hash ( std::uint64_t *  hash,
std::uint16_t const &  otherKey = 0 
) const

computes a fast uint64 hash mixing in another 16bit value

◆ hash32()

std::uint32_t const& senf::MACAddress::hash32 ( ) const

◆ local() [1/2]

bool senf::MACAddress::local ( ) const

true, if address is locally administered

◆ local() [2/2]

void senf::MACAddress::local ( bool  flag)

◆ multicast() [1/2]

bool senf::MACAddress::multicast ( ) const

true, if address is a group/multicast address

◆ multicast() [2/2]

void senf::MACAddress::multicast ( bool  flag)

◆ nic() [1/2]

std::uint32_t senf::MACAddress::nic ( ) const

Return last 3 bytes of the address.

◆ nic() [2/2]

void senf::MACAddress::nic ( std::uint32_t  oui)

Sets last 3 bytes of the address.

◆ operator bool()

senf::MACAddress::operator bool ( ) const
explicit

true, if address is not the zero address

◆ operator<()

bool senf::MACAddress::operator< ( MACAddress const &  other) const

◆ operator==()

bool senf::MACAddress::operator== ( EUI64 const &  eui64) const

◆ oui() [1/2]

std::uint32_t senf::MACAddress::oui ( ) const

Return first 3 bytes of the address.

◆ oui() [2/2]

void senf::MACAddress::oui ( std::uint32_t  oui)

Sets first 3 bytes of the address.

◆ uint64()

std::uint64_t senf::MACAddress::uint64 ( ) const

Return MAC address as uint64 value.

Friends And Related Function Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
MACAddress const &  mac 
)
related

Output MAC instance as it's string representation.

◆ operator>>()

std::istream & operator>> ( std::istream &  is,
MACAddress mac 
)
related

Try to initialize MACAddress instance from a string representation sets std::ios::failbit on the stream if an error occurred.

See also
MACAddress from_string()

Member Data Documentation

◆ Broadcast

senf::MACAddress const senf::MACAddress::Broadcast = senf::MACAddress(0xFFFFFFFFFFFFull)
static

The broadcast address.

Definition at line 75 of file MACAddress.hh.

◆ None

senf::MACAddress const senf::MACAddress::None
static

The empty (0) address.

Definition at line 76 of file MACAddress.hh.


The documentation for this struct was generated from the following files: