PcapPlusPlus  21.05
pcpp::IPv6Address Class Reference

#include <IpAddress.h>

Public Member Functions

 IPv6Address ()
 
 IPv6Address (const uint8_t bytes[16])
 
 IPv6Address (const std::string &addrAsString)
 
const uint8_t * toBytes () const
 
std::string toString () const
 
bool isMulticast () const
 
bool isValid () const
 
bool operator== (const IPv6Address &rhs) const
 
bool operator< (const IPv6Address &rhs) const
 
bool operator!= (const IPv6Address &rhs) const
 
void copyTo (uint8_t **arr, size_t &length) const
 
void copyTo (uint8_t *arr) const
 
bool matchSubnet (const IPv6Address &subnet, uint8_t prefixLength) const
 

Static Public Attributes

static const IPv6Address Zero
 
static const IPv6Address MulticastRangeLowerBound
 

Detailed Description

Represents an IPv6 address (of type xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx).

Constructor & Destructor Documentation

◆ IPv6Address() [1/3]

pcpp::IPv6Address::IPv6Address ( )
inline

A default constructor that creates an instance of the class with unspecified/zero address

◆ IPv6Address() [2/3]

pcpp::IPv6Address::IPv6Address ( const uint8_t  bytes[16])
inline

A constructor that creates an instance of the class out of 16-byte array.

Parameters
[in]bytesThe address as 16-byte array in network byte order

◆ IPv6Address() [3/3]

pcpp::IPv6Address::IPv6Address ( const std::string &  addrAsString)

A constructor that creates an instance of the class out of std::string value If the string doesn't represent a valid IPv6 address, an instance will store an unspecified address

Parameters
[in]addrAsStringThe std::string representation of the address

Member Function Documentation

◆ copyTo() [1/2]

void pcpp::IPv6Address::copyTo ( uint8_t **  arr,
size_t &  length 
) const

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

Parameters
[in]arrA pointer to where array will be allocated
[out]lengthReturns the length in bytes of the array that was allocated

◆ copyTo() [2/2]

void pcpp::IPv6Address::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 16 (the size of an IPv6 address)

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

◆ isMulticast()

bool pcpp::IPv6Address::isMulticast ( ) const

Determine whether the address is a multicast address

Returns
True if an address is multicast

◆ isValid()

bool pcpp::IPv6Address::isValid ( ) const
inline

Determine whether the address is unspecified

◆ matchSubnet()

bool pcpp::IPv6Address::matchSubnet ( const IPv6Address subnet,
uint8_t  prefixLength 
) const

Checks whether the address matches a subnet. For example: if subnet is 2001:3CA1:010F:001A::, prefixLength is 64, and address is 2001:3CA1:010F:001A:121B:0000:0000:0010, then the method will return true Another example: if subnet is 2001:3CA1:010F:001A::, prefixLength is 70 and address is 2001:3CA1:010F:001A:121B:0000:0000:0010 then the method will return false

Parameters
[in]subnetThe subnet to be verified
[in]prefixLengthHow many bits to use in the mask

◆ operator!=()

bool pcpp::IPv6Address::operator!= ( const IPv6Address rhs) const
inline

Overload of the not-equal-to operator

◆ operator<()

bool pcpp::IPv6Address::operator< ( const IPv6Address rhs) const
inline

Overload of the less-than operator

◆ operator==()

bool pcpp::IPv6Address::operator== ( const IPv6Address rhs) const
inline

Overload of the equal-to operator

◆ toBytes()

const uint8_t* pcpp::IPv6Address::toBytes ( ) const
inline

Returns a pointer to 16-byte array representing the IPv6 address

◆ toString()

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

Returns a std::string representation of the address

Returns
A string representation of the address

Member Data Documentation

◆ MulticastRangeLowerBound

const IPv6Address pcpp::IPv6Address::MulticastRangeLowerBound
static

A static value representing the lower bound of IPv6 multicast ranges. The bound is inclusive. MulticastRangeLowerBound is initialized to "ff00:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0". In order to check whether the address is a multicast address the isMulticast method can be used.

◆ Zero

const IPv6Address pcpp::IPv6Address::Zero
static

A static value representing a zero value of IPv6 address, meaning address of value "0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0" Notice this value can be omitted in the user code because the default constructor creates an instance with an unspecified/zero address. In order to check whether the address is zero the method isValid can be used