join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::MacAddress Class Reference

MAC address class. More...

#include <macaddress.hpp>

Collaboration diagram for join::MacAddress:

Public Types

using CaseConvert = std::ios_base& (std::ios_base&)
 case conversion function.
 
using iterator = std::array <uint8_t, IFHWADDRLEN>::iterator
 iterator from nested container.
 
using const_iterator = std::array <uint8_t, IFHWADDRLEN>::const_iterator
 constant iterator from nested container.
 

Public Member Functions

 MacAddress ()
 create the MacAddress instance (wilcard address).
 
 MacAddress (const MacAddress &address)
 create the MacAddress instance by copy.
 
 MacAddress (MacAddress &&address)
 create the MacAddress instance by move.
 
 MacAddress (const uint8_t *address, size_t size)
 create the MacAddress instance using an array.
 
 MacAddress (const uint8_t(&address)[IFHWADDRLEN])
 create the MacAddress instance using an array.
 
 MacAddress (std::initializer_list< uint8_t > address)
 create the MacAddress instance using an initialization list.
 
 MacAddress (const struct sockaddr &address)
 create the MacAddress instance using a sockaddr structure.
 
 MacAddress (const char *address)
 create the MacAddress instance using a string.
 
 MacAddress (const std::string &address)
 create the MacAddress instance using a string.
 
 ~MacAddress ()=default
 destroy the MacAddress instance.
 
int family () const
 get address family.
 
const uint8_t * addr () const
 get the internal MAC address array address.
 
socklen_t length () const
 get the size in byte of the internal MAC address array.
 
bool isWildcard () const
 check if MAC address is a wildcard address.
 
bool isBroadcast () const
 check if MAC address is a broadcast address.
 
std::string toString (CaseConvert caseConvert=std::nouppercase) const
 convert internal address array to string.
 
IpAddress toIpv6 (const IpAddress &prefix, int len) const
 convert MAC address to IPv6 address using prefix.
 
IpAddress toLinkLocalIpv6 () const
 convert MAC address to a link local IPv6 address.
 
IpAddress toUniqueLocalIpv6 () const
 convert MAC address to a unique local IPv6 address using eui-64.
 
void clear ()
 clear MAC address (wilcard address).
 
iterator begin ()
 returns an iterator to the first element of the nested container.
 
const_iterator begin () const
 returns an iterator to the first element of the nested container.
 
const_iterator cbegin () const
 returns an iterator to the first element of the nested container.
 
iterator end ()
 return an iterator to the element following the last element of the nested container.
 
const_iterator end () const
 return an iterator to the element following the last element of the nested container.
 
const_iterator cend () const
 return an iterator to the element following the last element of the nested container.
 
MacAddressoperator= (const MacAddress &address)
 assign the MacAddress instance by copy.
 
MacAddressoperator= (MacAddress &&address)
 assign the MacAddress instance by move.
 
MacAddressoperator= (std::initializer_list< uint8_t > address)
 assign the MacAddress using an initialization list.
 
MacAddressoperator= (const struct sockaddr &address)
 assign the MacAddress using a sockaddr structure.
 
MacAddressoperator+= (int value)
 add the provided value to the current MAC address.
 
MacAddressoperator++ ()
 perform pre-increment operation on MAC address.
 
MacAddress operator++ (int)
 perform post-increment operation on MAC address.
 
uint8_t & operator[] (size_t position)
 returns a reference to the element at the specified location.
 
const uint8_t & operator[] (size_t position) const
 returns a reference to the element at the specified location.
 
MacAddress operator~ () const
 perform NOT operation on MAC address.
 

Static Public Member Functions

static bool isMacAddress (const std::string &address)
 check if the specified string is a MAC address.
 
static MacAddress address (const std::string &interface)
 get the specified interface MAC address.
 

Static Public Attributes

static const MacAddress wildcard = "00:00:00:00:00:00"
 wildcard MAC address.
 
static const MacAddress broadcast = "ff:ff:ff:ff:ff:ff"
 broadcast MAC address.
 

Detailed Description

MAC address class.

Member Typedef Documentation

◆ CaseConvert

using join::MacAddress::CaseConvert = std::ios_base& (std::ios_base&)

case conversion function.

◆ const_iterator

using join::MacAddress::const_iterator = std::array <uint8_t, IFHWADDRLEN>::const_iterator

constant iterator from nested container.

◆ iterator

using join::MacAddress::iterator = std::array <uint8_t, IFHWADDRLEN>::iterator

iterator from nested container.

Constructor & Destructor Documentation

◆ MacAddress() [1/9]

MacAddress::MacAddress ( )

create the MacAddress instance (wilcard address).

◆ MacAddress() [2/9]

MacAddress::MacAddress ( const MacAddress & address)

create the MacAddress instance by copy.

Parameters
addressMAC address to copy.

◆ MacAddress() [3/9]

MacAddress::MacAddress ( MacAddress && address)

create the MacAddress instance by move.

Parameters
addressMAC address to move.

◆ MacAddress() [4/9]

MacAddress::MacAddress ( const uint8_t * address,
size_t size )

create the MacAddress instance using an array.

Parameters
addressMAC address array.
sizeMAC address array size.
Exceptions
invalid_argumentif out of range.

◆ MacAddress() [5/9]

MacAddress::MacAddress ( const uint8_t(&) address[IFHWADDRLEN])

create the MacAddress instance using an array.

Parameters
addressMAC address array.
Exceptions
invalid_argumentif out of range.

◆ MacAddress() [6/9]

MacAddress::MacAddress ( std::initializer_list< uint8_t > address)

create the MacAddress instance using an initialization list.

Parameters
addressMAC address initialization list.
Exceptions
invalid_argumentif out of range.

◆ MacAddress() [7/9]

MacAddress::MacAddress ( const struct sockaddr & address)

create the MacAddress instance using a sockaddr structure.

Parameters
addressaddress structure to use.
Exceptions
invalid_argumentif address is wrong.

◆ MacAddress() [8/9]

MacAddress::MacAddress ( const char * address)

create the MacAddress instance using a string.

Parameters
addressMAC address string to parse.
Exceptions
invalid_argumentif MAC address is invalid.

◆ MacAddress() [9/9]

MacAddress::MacAddress ( const std::string & address)

create the MacAddress instance using a string.

Parameters
addressMAC address string to parse.
Exceptions
invalid_argumentif MAC address is invalid.

◆ ~MacAddress()

join::MacAddress::~MacAddress ( )
default

destroy the MacAddress instance.

Member Function Documentation

◆ addr()

const uint8_t * MacAddress::addr ( ) const

get the internal MAC address array address.

Returns
A pointer to the internal MAC address array.

◆ address()

MacAddress MacAddress::address ( const std::string & interface)
static

get the specified interface MAC address.

Parameters
interfaceinterface name.
Returns
the specified interface MAC address.

◆ begin() [1/2]

MacAddress::iterator MacAddress::begin ( )

returns an iterator to the first element of the nested container.

Returns
iterator to the first element.

◆ begin() [2/2]

MacAddress::const_iterator MacAddress::begin ( ) const

returns an iterator to the first element of the nested container.

Returns
iterator to the first element.

◆ cbegin()

MacAddress::const_iterator MacAddress::cbegin ( ) const

returns an iterator to the first element of the nested container.

Returns
iterator to the first element.

◆ cend()

MacAddress::const_iterator MacAddress::cend ( ) const

return an iterator to the element following the last element of the nested container.

Returns
iterator to the element following the last element.

◆ clear()

void MacAddress::clear ( )

clear MAC address (wilcard address).

◆ end() [1/2]

MacAddress::iterator MacAddress::end ( )

return an iterator to the element following the last element of the nested container.

Returns
iterator to the element following the last element.

◆ end() [2/2]

MacAddress::const_iterator MacAddress::end ( ) const

return an iterator to the element following the last element of the nested container.

Returns
iterator to the element following the last element.

◆ family()

int MacAddress::family ( ) const

get address family.

Returns
ARPHRD_ETHER.

◆ isBroadcast()

bool MacAddress::isBroadcast ( ) const

check if MAC address is a broadcast address.

Returns
if broadcast true is returned, false otherwise.

◆ isMacAddress()

bool MacAddress::isMacAddress ( const std::string & address)
static

check if the specified string is a MAC address.

Parameters
addressstring that may contain a MAC address.
Returns
true if the specified string is a MAC address, false otherwise.

◆ isWildcard()

bool MacAddress::isWildcard ( ) const

check if MAC address is a wildcard address.

Returns
if wildcard true is returned, false otherwise.

◆ length()

socklen_t MacAddress::length ( ) const

get the size in byte of the internal MAC address array.

Returns
The size in byte of the internal MAC address array.

◆ operator++() [1/2]

MacAddress & MacAddress::operator++ ( )

perform pre-increment operation on MAC address.

Returns
a reference of the current object.

◆ operator++() [2/2]

MacAddress MacAddress::operator++ ( int )

perform post-increment operation on MAC address.

Returns
a copy of the original object.

◆ operator+=()

MacAddress & MacAddress::operator+= ( int value)

add the provided value to the current MAC address.

Parameters
valuevalue to add to the current MAC address.
Returns
a reference of the current object.

◆ operator=() [1/4]

MacAddress & MacAddress::operator= ( const MacAddress & address)

assign the MacAddress instance by copy.

Parameters
addressMAC address to copy.
Returns
a reference of the current object.

◆ operator=() [2/4]

MacAddress & MacAddress::operator= ( const struct sockaddr & address)

assign the MacAddress using a sockaddr structure.

Parameters
addressaddress structure to use.
Returns
a reference of the current object.
Exceptions
invalid_argumentif address is wrong.

◆ operator=() [3/4]

MacAddress & MacAddress::operator= ( MacAddress && address)

assign the MacAddress instance by move.

Parameters
addressMAC address to move.
Returns
a reference of the current object.

◆ operator=() [4/4]

MacAddress & MacAddress::operator= ( std::initializer_list< uint8_t > address)

assign the MacAddress using an initialization list.

Parameters
addressMAC address initialization list.
Returns
a reference of the current object.
Exceptions
invalid_argumentif out of range.

◆ operator[]() [1/2]

uint8_t & MacAddress::operator[] ( size_t position)

returns a reference to the element at the specified location.

Parameters
positionposition of the element to return.
Returns
peference to the requested element.
Exceptions
invalid_argumentif position is out of range.

◆ operator[]() [2/2]

const uint8_t & MacAddress::operator[] ( size_t position) const

returns a reference to the element at the specified location.

Parameters
positionposition of the element to return.
Returns
reference to the requested element.
Exceptions
invalid_argumentif position is out of range.

◆ operator~()

MacAddress MacAddress::operator~ ( ) const

perform NOT operation on MAC address.

Returns
result of NOT operation on MacAddress.

◆ toIpv6()

IpAddress MacAddress::toIpv6 ( const IpAddress & prefix,
int len ) const

convert MAC address to IPv6 address using prefix.

Parameters
prefixprefix address.
lenprefix length.
Returns
IPv6 address.

◆ toLinkLocalIpv6()

IpAddress MacAddress::toLinkLocalIpv6 ( ) const

convert MAC address to a link local IPv6 address.

Returns
IPv6 link local address.

◆ toString()

std::string MacAddress::toString ( CaseConvert caseConvert = std::nouppercase) const

convert internal address array to string.

Parameters
_casecase conversion function (default: std::nouppercase).
Returns
the internal address array converted to string.

◆ toUniqueLocalIpv6()

IpAddress MacAddress::toUniqueLocalIpv6 ( ) const

convert MAC address to a unique local IPv6 address using eui-64.

Returns
IPv6 unique local address.

Member Data Documentation

◆ broadcast

const MacAddress MacAddress::broadcast = "ff:ff:ff:ff:ff:ff"
static

broadcast MAC address.

Broadcast MAC address.

◆ wildcard

const MacAddress MacAddress::wildcard = "00:00:00:00:00:00"
static

wildcard MAC address.

Wildcard MAC address.


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