PcapPlusPlus
pcpp::TLVRecord Class Referenceabstract

#include <TLVData.h>

Inheritance diagram for pcpp::TLVRecord:
pcpp::DhcpOption pcpp::IPv4Option pcpp::IPv6TLVOptionHeader::IPv6Option pcpp::RadiusAttribute pcpp::TcpOption

Classes

struct  TLVRawData
 

Public Member Functions

 TLVRecord (uint8_t *recordRawData)
 
 TLVRecord (const TLVRecord &other)
 
virtual ~TLVRecord ()
 
TLVRecordoperator= (const TLVRecord &other)
 
bool operator== (const TLVRecord &rhs)
 
uint8_t getType ()
 
uint8_t * getValue ()
 
bool isNull ()
 
bool isNotNull ()
 
uint8_t * getRecordBasePtr ()
 
void purgeRecordData ()
 
template<typename T >
getValueAs (size_t offset=0)
 
template<typename T >
bool setValue (T newValue, int valueOffset=0)
 
virtual size_t getTotalSize () const =0
 
virtual size_t getDataSize ()=0
 

Detailed Description

A wrapper class for a Type-Length-Value (TLV) record. This class does not create or modify TLV records, but rather serves as a wrapper and provides useful methods for retrieving data from them. This class has several abstract methods that should be implemented in derived classes. These methods are for record length value calculation (the 'L' in TLV) which is implemented differently in different protocols

Constructor & Destructor Documentation

◆ TLVRecord() [1/2]

pcpp::TLVRecord::TLVRecord ( uint8_t *  recordRawData)
inline

A c'tor for this class that gets a pointer to the TLV record raw data (byte array)

Parameters
[in]recordRawDataA pointer to the TLV record raw data

◆ TLVRecord() [2/2]

pcpp::TLVRecord::TLVRecord ( const TLVRecord other)
inline

A copy c'tor for this class. This copy c'tor doesn't copy the TLV data, but only the pointer to it, which means that after calling it both the old and the new instance will point to the same TLV raw data

Parameters
[in]otherThe TLVRecord instance to copy from

◆ ~TLVRecord()

virtual pcpp::TLVRecord::~TLVRecord ( )
inlinevirtual

A d'tor for this class, currently does nothing

Member Function Documentation

◆ getDataSize()

virtual size_t pcpp::TLVRecord::getDataSize ( )
pure virtual
Returns
The size of the record value (meaning the size of the 'V' part in TLV)

Implemented in pcpp::DhcpOption, pcpp::IPv4Option, pcpp::TcpOption, pcpp::IPv6TLVOptionHeader::IPv6Option, and pcpp::RadiusAttribute.

◆ getRecordBasePtr()

uint8_t* pcpp::TLVRecord::getRecordBasePtr ( )
inline
Returns
A pointer to the TLV record raw data byte stream

◆ getTotalSize()

virtual size_t pcpp::TLVRecord::getTotalSize ( ) const
pure virtual
Returns
The total size of the TLV record (in bytes)

Implemented in pcpp::DhcpOption, pcpp::IPv4Option, pcpp::TcpOption, pcpp::IPv6TLVOptionHeader::IPv6Option, and pcpp::RadiusAttribute.

◆ getType()

uint8_t pcpp::TLVRecord::getType ( )
inline
Returns
The type field of the record (the 'T' in Type-Length-Value)

◆ getValue()

uint8_t* pcpp::TLVRecord::getValue ( )
inline
Returns
A pointer to the value of the record as byte array (the 'V' in Type-Length- Value)

◆ getValueAs()

template<typename T >
T pcpp::TLVRecord::getValueAs ( size_t  offset = 0)
inline

A templated method to retrieve the record data as a certain type T. For example, if record data is 4B long (integer) then this method should be used as getValueAs<int>() and it will return the record data as an integer.
Notice this return value is a copy of the data, not a pointer to the actual data

Parameters
[in]offsetThe offset in the record data to start reading the value from. Useful for cases when you want to read some of the data that doesn't start at offset 0. This is an optional parameter and the default value is 0, meaning start reading the value at the beginning of the record data
Returns
The record data as type T

◆ isNotNull()

bool pcpp::TLVRecord::isNotNull ( )
inline
Returns
True if the TLV record raw data is not NULL, false otherwise

◆ isNull()

bool pcpp::TLVRecord::isNull ( )
inline
Returns
True if the TLV record raw data is NULL, false otherwise

◆ operator=()

TLVRecord& pcpp::TLVRecord::operator= ( const TLVRecord other)
inline

Overload of the assignment operator. This operator doesn't copy the TLV data, but rather copies the pointer to it, which means that after calling it both the old and the new instance will point to the same TLV raw data

Parameters
[in]otherThe TLVRecord instance to assign

◆ operator==()

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

Overload of the equality operator. Two record are equal if both of them point to the same data, or if they point to different data but their total size is equal and the raw data they both contain is similar.

Parameters
[in]rhsThe object to compare to
Returns
True if both objects are equal, false otherwise

◆ purgeRecordData()

void pcpp::TLVRecord::purgeRecordData ( )
inline

Free the memory of the TLV record raw data

◆ setValue()

template<typename T >
bool pcpp::TLVRecord::setValue ( newValue,
int  valueOffset = 0 
)
inline

A templated method to copy data of type T into the TLV record data. For example: if record data is 4[Bytes] long use this method with <int> to set an integer value into the record data: setValue<int>(num)

Parameters
[in]newValueThe value of type T to copy to the record data
[in]valueOffsetAn optional parameter that specifies where to start setting the record data (default set to 0). For example: if record data is 20 bytes long and you only need to set the 4 last bytes as integer then use this method like this: setValue<int>(num, 16)
Returns
True if value was set successfully or false if the size of T is larger than the record data size