PcapPlusPlus  Next
pcpp::IPv6Address Class Reference

#include <IpAddress.h>

Public Member Functions

 IPv6Address ()=default
 A default constructor that creates an instance of the class with the zero-initialized address.
 
 IPv6Address (const uint8_t bytes[16])
 
 IPv6Address (const uint8_t *bytes, size_t size)
 A constructor that creates an instance of the class out of a 16-byte array. More...
 
 IPv6Address (const std::array< uint8_t, 16 > &bytes)
 
 IPv6Address (const std::string &addrAsString)
 
const uint8_t * toBytes () const
 
const std::array< uint8_t, 16 > & toByteArray () const
 
std::string toString () const
 
bool isMulticast () 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
 
size_t copyTo (uint8_t *buffer, size_t size) const
 Copies the address value to a user-provided buffer. More...
 
bool copyToNewBuffer (uint8_t **buffer, size_t &size) const
 Allocates a new buffer and copies the address value to it. The user is responsible for deallocating the buffer. More...
 
bool matchNetwork (const IPv6Network &network) const
 
bool matchNetwork (const std::string &network) const
 

Static Public Member Functions

static bool isValidIPv6Address (const std::string &addrAsString)
 

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/4]

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
Remarks
This constructor assumes that the provided array is exactly 16 bytes long. Prefer using the constructor with size parameter if the array length is not guaranteed to be 16 bytes.

◆ IPv6Address() [2/4]

pcpp::IPv6Address::IPv6Address ( const uint8_t *  bytes,
size_t  size 
)

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

Parameters
bytesThe address as 16-byte array in network byte order
sizeThe size of the array in bytes
Exceptions
std::invalid_argumentIf the provided buffer is null.
std::out_of_rangeIf the provided size is smaller than 16 bytes.

◆ IPv6Address() [3/4]

pcpp::IPv6Address::IPv6Address ( const std::array< uint8_t, 16 > &  bytes)
inline

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

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

◆ IPv6Address() [4/4]

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

A constructor that creates an instance of the class out of std::string value.

Parameters
[in]addrAsStringThe std::string representation of the address
Exceptions
std::invalid_argumentThe provided string does not represent a valid IPv6 address.

Member Function Documentation

◆ copyTo() [1/3]

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
Exceptions
std::invalid_argumentIf the provided pointer is null.
Deprecated:
Use copyToNewBuffer instead.

◆ copyTo() [2/3]

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
Remarks
This method assumes that the provided array is at least 16 bytes long. Prefer using the copyTo(uint8_t* buffer, size_t size) method if the array length is not guaranteed to be 16 bytes.

◆ copyTo() [3/3]

size_t pcpp::IPv6Address::copyTo ( uint8_t *  buffer,
size_t  size 
) const

Copies the address value to a user-provided buffer.

This function supports querying. If the buffer is null and size is zero, it returns the required size.

Parameters
[in]bufferA pointer to the buffer where the address will be copied
[in]sizeThe size of the buffer in bytes
Returns
The number of bytes copied to the buffer or the number of required bytes, which is always 16 for IPv6 addresses.
Exceptions
std::invalid_argumentIf the provided buffer is null and size is not zero.

◆ copyToNewBuffer()

bool pcpp::IPv6Address::copyToNewBuffer ( uint8_t **  buffer,
size_t &  size 
) const

Allocates a new buffer and copies the address value to it. The user is responsible for deallocating the buffer.

Parameters
bufferA pointer to a pointer where the new buffer will be allocated
sizeA reference to a size_t variable that will be updated with the size of the allocated buffer
Returns
True if the buffer was successfully allocated and the address was copied, false otherwise.
Exceptions
std::invalid_argumentIf the buffer pointer is null.

◆ isMulticast()

bool pcpp::IPv6Address::isMulticast ( ) const

Determine whether the address is a multicast address

Returns
True if an address is multicast

◆ isValidIPv6Address()

static bool pcpp::IPv6Address::isValidIPv6Address ( const std::string &  addrAsString)
static

A static method that checks whether a string represents a valid IPv6 address

Parameters
[in]addrAsStringThe std::string representation of the address
Returns
True if the address is valid, false otherwise

◆ matchNetwork() [1/2]

bool pcpp::IPv6Address::matchNetwork ( const IPv6Network network) const

Checks whether the address matches a network.

Parameters
networkAn IPv6Network network
Returns
True if the address matches the network or false otherwise

◆ matchNetwork() [2/2]

bool pcpp::IPv6Address::matchNetwork ( const std::string &  network) const

Checks whether the address matches a network. For example: this method will return true for address d6e5:83dc:0c58:bc5d:1449:5898:: and network which is one of: d6e5:83dc:0c58:bc5d::/64, d6e5:83dc:0c58:bc5d::/ffff:ffff:ffff:ffff:: Another example: this method will return false for address d6e5:83dc:: and network which is one of: d6e5:83dc:0c58:bc5d::/64, d6e5:83dc:0c58:bc5d::/ffff:ffff:ffff:ffff::

Parameters
[in]networkA string in one of these formats:
  • IPV6_ADDRESS/Y where IPV6_ADDRESS is a valid IPv6 address and Y is a number between 0 and 128
  • IPV6_ADDRESS/IPV6_NETMASK where IPV6_ADDRESS is a valid IPv6 address and IPV6_NETMASK is a valid IPv6 netmask
Returns
True if the address matches the network or false if it doesn't or if the network is invalid

◆ operator!=()

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

Overload of the not-equal-to operator

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

◆ operator<()

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

Overload of the less-than operator

Parameters
[in]rhsThe object to compare with
Returns
True if the address value is lower than the other address value, false otherwise

◆ operator==()

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

Overload of the equal-to operator

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

◆ toByteArray()

const std::array<uint8_t, 16>& pcpp::IPv6Address::toByteArray ( ) const
inline

Returns a view of the IPv6 address as a std::array of bytes

Returns
A reference to a 16-byte standard array representing the IPv6 address

◆ toBytes()

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

Returns a view of the IPv6 address as a 16-byte raw C-style array

Returns
A non-owning 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".