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

The Ethernet MAC is modeled as a fixed-size container/sequence of 6 bytes. A MACAddress can be converted from/to the following representations
boost::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[]:
senf::MACAddress mac (...); std::vector<char> data; data.resize(6); std::copy(mac.begin(), mac.end(), data.begin()); // Copy 6 bytes
from_ members) instead of ordinarily overloaded constructors for one simple reason: char * 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 82 of file MACAddress.hh.
Public Member Functions |
|
| MACAddress () | |
| Construct zero-initialized address. |
|
| MACAddress (senf::NoInit_t) | |
| Construct uninitialized (!) address. |
|
| MACAddress (boost::uint64_t v) | |
| Construct MACAddress constants. |
|
| bool | local () const |
true, if address is locally administered |
|
| bool | multicast () const |
true, if address is a group/multicast address |
|
| bool | broadcast () const |
true, if address is the broadcast address |
|
| bool | boolean_test () const |
true, if address is not the zero address |
|
| boost::uint32_t | oui () const |
| Return first 3 bytes of the address. |
|
| boost::uint32_t | nic () const |
| Return last 3 bytes of the address. |
|
| boost::uint64_t | eui64 () const |
| Build EUI-64 from the MAC address. |
|
| boost::uint64_t | uint64 () const |
| Return MAC address as uint64 value. |
|
Static Public Member Functions |
|
| static MACAddress | from_string (std::string const &s) |
| Construct address from string representation. |
|
| template<class InputIterator > | |
| static MACAddress | from_data (InputIterator i) |
| Construct address from raw data. |
|
| static MACAddress | from_eui64 (senf::EUI64 const &eui) |
| Construct address from EUI-64. |
|
Static Public Attributes |
|
| static MACAddress const | Broadcast = senf::MACAddress(0xFFFFFFFFFFFFull) |
| The broadcast address. |
|
| static MACAddress const | None |
| The empty (0) address. |
|
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. |
|
| std::istream & | operator>> (std::istream &os, MACAddress &mac) |
| Try to initialize MACAddress instance from a string representation sets std::ios::failbit on the stream if an error occurred. |
|
| senf::MACAddress:: | ||||
| MACAddress | () | |||
Construct zero-initialized address.
Definition at line 37 of file MACAddress.cci.
| senf::MACAddress:: | ||||
| MACAddress | ( | senf::NoInit_t | ) | |
Construct uninitialized (!) address.
Definition at line 42 of file MACAddress.cci.
| senf::MACAddress:: | ||||
| MACAddress | ( | boost::uint64_t | v | ) |
Construct MACAddress constants.
Definition at line 45 of file MACAddress.cci.
| bool senf::MACAddress:: | ||||
| boolean_test | () | |||
true, if address is not the zero address
Definition at line 74 of file MACAddress.cci.
| bool senf::MACAddress:: | ||||
| broadcast | () | |||
true, if address is the broadcast address
Definition at line 67 of file MACAddress.cci.
| boost::uint64_t senf::MACAddress:: | ||||
| eui64 | () | |||
Build EUI-64 from the MAC address.
Definition at line 99 of file MACAddress.cci.
| senf::MACAddress senf::MACAddress:: | ||||
| from_data | ( | InputIterator | i | ) |
Construct address from raw data.
Copies the data from i into the MAC address.
Definition at line 38 of file MACAddress.ct.
| senf::MACAddress senf::MACAddress:: | ||||
| from_eui64 | ( | senf::EUI64 const & | eui | ) |
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.
| AddressSyntaxException | if eui is not a MAC compatible EUI-64. |
Definition at line 50 of file MACAddress.cc.
| senf::MACAddress senf::MACAddress:: | ||||
| from_string | ( | std::string const & | s | ) |
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.
| AddressSyntaxException |
Definition at line 43 of file MACAddress.cc.
| bool senf::MACAddress:: | ||||
| local | () | |||
true, if address is locally administered
Definition at line 55 of file MACAddress.cci.
| bool senf::MACAddress:: | ||||
| multicast | () | |||
true, if address is a group/multicast address
Definition at line 61 of file MACAddress.cci.
| boost::uint32_t senf::MACAddress:: | ||||
| nic | () | |||
Return last 3 bytes of the address.
Definition at line 90 of file MACAddress.cci.
| boost::uint32_t senf::MACAddress:: | ||||
| oui | () | |||
Return first 3 bytes of the address.
Definition at line 81 of file MACAddress.cci.
| boost::uint64_t senf::MACAddress:: | ||||
| uint64 | () | |||
Return MAC address as uint64 value.
Definition at line 112 of file MACAddress.cci.
| std::ostream & | ||||
| operator<< | ( | std::ostream & | os, | |
| MACAddress const & | mac | ) | ||
Output MAC instance as it's string representation.
| std::istream & | ||||
| operator>> | ( | std::istream & | os, | |
| MACAddress & | mac | ) | ||
Try to initialize MACAddress instance from a string representation sets std::ios::failbit on the stream if an error occurred.
| senf::MACAddress const senf::MACAddress::Broadcast = senf::MACAddress(0xFFFFFFFFFFFFull) | ||||
| [static] | ||||
The broadcast address.
Definition at line 86 of file MACAddress.hh.
| senf::MACAddress const senf::MACAddress::None | ||||
| [static] | ||||
The empty (0) address.
Definition at line 87 of file MACAddress.hh.