PcapPlusPlus  24.09
pcpp::MacAddress Class Reference

#include <MacAddress.h>

Public Member Functions

 MacAddress ()=default
 
 MacAddress (const uint8_t *addr)
 
 MacAddress (const std::string &addr)
 
template<typename T , typename = typename std::enable_if<std::is_convertible<T, std::string>::value>::type>
 MacAddress (const T &addr)
 
 MacAddress (uint8_t firstOctet, uint8_t secondOctet, uint8_t thirdOctet, uint8_t fourthOctet, uint8_t fifthOctet, uint8_t sixthOctet)
 
 MacAddress (std::initializer_list< uint8_t > octets)
 
bool operator== (const MacAddress &other) const
 
bool operator!= (const MacAddress &other) const
 
MacAddressoperator= (std::initializer_list< uint8_t > octets)
 
const uint8_t * getRawData () const
 
std::string toString () const
 
void copyTo (uint8_t **arr) const
 
void copyTo (uint8_t *arr) const
 

Static Public Attributes

static MacAddress Zero
 

Detailed Description

Represents L2 MAC addresses. Can be constructed from string or a series of 6 byte octets

Constructor & Destructor Documentation

◆ MacAddress() [1/6]

pcpp::MacAddress::MacAddress ( )
default

Default constructor for this class. Initializes the address as 00:00:00:00:00:00.

◆ MacAddress() [2/6]

pcpp::MacAddress::MacAddress ( const uint8_t *  addr)
inlineexplicit

A constructor that creates an instance of the class out of a byte array. The byte array length should be 6 (as MAC address is 6-byte long), and the remaining bytes are ignored. If the byte array is invalid, the constructor throws an exception.

Parameters
[in]addrA pointer to the byte array containing 6 bytes representing the MAC address

◆ MacAddress() [3/6]

pcpp::MacAddress::MacAddress ( const std::string &  addr)
explicit

A constructor that creates an instance of the class out of a std::string. If the string doesn't represent a valid MAC address, the constructor throws an exception.

Parameters
[in]addrthe string representing the MAC address in format "00:00:00:00:00:00"

◆ MacAddress() [4/6]

template<typename T , typename = typename std::enable_if<std::is_convertible<T, std::string>::value>::type>
pcpp::MacAddress::MacAddress ( const T &  addr)
inline

A template constructor that creates an instance of the class out of a string convertible to std::string. If the string doesn't represent a valid MAC address, the constructor throws an exception.

Parameters
[in]addrthe string representing the MAC address in format "00:00:00:00:00:00"

◆ MacAddress() [5/6]

pcpp::MacAddress::MacAddress ( uint8_t  firstOctet,
uint8_t  secondOctet,
uint8_t  thirdOctet,
uint8_t  fourthOctet,
uint8_t  fifthOctet,
uint8_t  sixthOctet 
)
inline

A constructor that creates an instance of 6 bytes representing the MAC address

Parameters
[in]firstOctetRepresent the first octet in the address
[in]secondOctetRepresent the second octet in the address
[in]thirdOctetRepresent the third octet in the address
[in]fourthOctetRepresent the fourth octet in the address
[in]fifthOctetRepresent the fifth octet in the address
[in]sixthOctetRepresent the sixth octet in the address

◆ MacAddress() [6/6]

pcpp::MacAddress::MacAddress ( std::initializer_list< uint8_t >  octets)
inline

A constructor that creates an instance out of the initializer list. The byte list length should be 6 (as MAC address is 6-byte long). If the list is invalid, the constructor throws an exception.

Parameters
[in]octetsAn initializer list containing the values of type uint8_t representing the MAC address

Member Function Documentation

◆ copyTo() [1/2]

void pcpp::MacAddress::copyTo ( uint8_t **  arr) const
inline

Allocates a byte array of length 6 and copies address value into it. Array deallocation is user responsibility

Parameters
[in]arrA pointer to where array will be allocated

◆ copyTo() [2/2]

void pcpp::MacAddress::copyTo ( uint8_t *  arr) const
inline

Gets a pointer to an already allocated byte array and copies the address value to it. This method assumes array allocated size is at least 6 (the size of a MAC address)

Parameters
[in]arrA pointer to the array which address will be copied to

◆ getRawData()

const uint8_t* pcpp::MacAddress::getRawData ( ) const
inline

Returns the pointer to raw data

Returns
The pointer to raw data

◆ operator!=()

bool pcpp::MacAddress::operator!= ( const MacAddress other) const
inline

Overload of the not-equal operator

Parameters
[in]otherThe object to compare with
Returns
True if addresses are not equal, false otherwise

◆ operator=()

MacAddress& pcpp::MacAddress::operator= ( std::initializer_list< uint8_t >  octets)
inline

Overload of the assignment operator. If the list is invalid, the constructor throws an exception.

Parameters
[in]octetsAn initializer list containing the values of type uint8_t representing the MAC address, the length of the list must be equal to 6

◆ operator==()

bool pcpp::MacAddress::operator== ( const MacAddress other) const
inline

Overload of the comparison operator.

Parameters
[in]otherThe object to compare with
Returns
True if addresses are equal, false otherwise

◆ toString()

std::string pcpp::MacAddress::toString ( ) const

Returns a std::string representation of the address

Returns
A string representation of the address

Member Data Documentation

◆ Zero

MacAddress pcpp::MacAddress::Zero
static

A static value representing a zero value of MAC address, meaning address of value "00:00:00:00:00:00"