PcapPlusPlus
pcpp::MacAddress Class Reference

#include <MacAddress.h>

Public Member Functions

 MacAddress (uint8_t *addr)
 
 MacAddress (const char *addr)
 
 MacAddress (const std::string &addr)
 
 MacAddress (uint8_t firstOctest, uint8_t secondOctet, uint8_t thirdOctet, uint8_t fourthOctet, uint8_t fifthOctet, uint8_t sixthOctet)
 
 MacAddress (const MacAddress &other)
 
MacAddressoperator= (const MacAddress &other)
 
bool operator== (const MacAddress &other)
 
bool operator!= (const MacAddress &other)
 
bool isValid ()
 
std::string toString ()
 
void copyTo (uint8_t **arr)
 
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/5]

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

A constructor that creates an instance of the class out of a byte array. The byte array length must be equal or greater to 6 (as MAC address is 6-byte long)

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

◆ MacAddress() [2/5]

pcpp::MacAddress::MacAddress ( const char *  addr)

A constructor that creates an instance of the class out of a (char*) string. If the string doesn't represent a valid MAC address, instance will be invalid, meaning isValid() will return false

Parameters
[in]addrA pointer to the (char*) string

◆ MacAddress() [3/5]

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

A constructor that creates an instance of the class out of a std::string. If the string doesn't represent a valid MAC address, instance will be invalid, meaning isValid() will return false

  • Parameters
    [in]addrA pointer to the string

◆ MacAddress() [4/5]

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

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

Parameters
[in]firstOctestRepresent 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() [5/5]

pcpp::MacAddress::MacAddress ( const MacAddress other)

A copy constructor for this class

Member Function Documentation

◆ copyTo() [1/2]

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

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

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

◆ isValid()

bool pcpp::MacAddress::isValid ( )
inline

Get an indication whether the MAC address is valid. An address can be invalid if it was constructed from illegal input, for example: invalid string

Returns
True if the address is valid, false otherwise

◆ operator!=()

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

Overload of the not-equal operator

Returns
true if 2 addresses are not equal. False otherwise

◆ operator=()

MacAddress& pcpp::MacAddress::operator= ( const MacAddress other)

Overload of the assignment operator

◆ operator==()

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

Overload of the comparison operator

Returns
true if 2 addresses are equal. False otherwise

◆ toString()

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

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"