Open Lighting Architecture  Latest Git
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
ola::network::MACAddress Class Reference

Detailed Description

Represents a MAC Address.

All methods use network byte order unless otherwise mentioned. TODO(Peter): Is the above actually true for MAC addresses?

Public Types

enum  { LENGTH = 6 }
 

Public Member Functions

 MACAddress (const uint8_t *address)
 Construct a new MAC address from binary data. More...
 
 MACAddress (const MACAddress &other)
 
MACAddressoperator= (const MACAddress &other)
 
bool operator== (const MACAddress &other) const
 
bool operator!= (const MACAddress &other) const
 
bool operator< (const MACAddress &other) const
 Order addresses. Note that this won't order how humans expect because ether_addr is in network byte order. TODO(Peter): Check if this is actually true for MAC Addresses.
 
bool operator> (const MACAddress &other) const
 
void Get (uint8_t ptr[LENGTH]) const
 
bool Pack (uint8_t *buffer, unsigned int length) const
 Write the binary representation of the MAC address to memory. More...
 
std::string ToString () const
 Convert a mac address to a human readable string. More...
 

Static Public Member Functions

static MACAddressFromString (const std::string &address)
 Convert a string to a MACAddress object. More...
 
static bool FromString (const std::string &address, MACAddress *target)
 Convert a string to a MACAddress object. More...
 
static MACAddress FromStringOrDie (const std::string &address)
 

Friends

std::ostream & operator<< (std::ostream &out, const MACAddress &address)
 

Constructor & Destructor Documentation

◆ MACAddress()

ola::network::MACAddress::MACAddress ( const uint8_t *  address)
explicit

Construct a new MAC address from binary data.

Parameters
addressa pointer to the memory containing the MAC address data. The data should be most significant byte first.

Member Function Documentation

◆ FromString() [1/2]

MACAddress * ola::network::MACAddress::FromString ( const std::string &  address)
static

Convert a string to a MACAddress object.

Parameters
addressa string in the form 'nn:nn:nn:nn:nn:nn' or 'nn.nn.nn.nn.nn.nn'
Returns
a pointer to a MACAddress object if it worked, NULL otherwise

◆ FromString() [2/2]

bool ola::network::MACAddress::FromString ( const std::string &  address,
MACAddress target 
)
static

Convert a string to a MACAddress object.

Parameters
addressa string in the form 'nn:nn:nn:nn:nn:nn' or 'nn.nn.nn.nn.nn.nn'
[out]targeta pointer to a MACAddress object
Returns
true if it worked, false otherwise

◆ Pack()

bool ola::network::MACAddress::Pack ( uint8_t *  buffer,
unsigned int  length 
) const
inline

Write the binary representation of the MAC address to memory.

Parameters
buffera pointer to memory to write the MAC address to
lengththe size of the memory block, should be at least LENGTH.
Returns
true if length was >= LENGTH, false otherwise.

◆ ToString()

string ola::network::MACAddress::ToString ( ) const

Convert a mac address to a human readable string.

Returns
a string

ether_ntoa_r doesn't exist on Mac, so can't use it; ether_ntoa isn't thread safe


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