PcapPlusPlus  22.05
pcpp::DhcpOption Class Reference

#include <DhcpLayer.h>

Inheritance diagram for pcpp::DhcpOption:
pcpp::TLVRecord< uint8_t, uint8_t >

Public Member Functions

 DhcpOption (uint8_t *optionRawData)
 
virtual ~DhcpOption ()
 
IPv4Address getValueAsIpAddr () const
 
void setValueIpAddr (const IPv4Address &addr, int valueOffset=0)
 
std::string getValueAsString (int valueOffset=0) const
 
void setValueString (const std::string &stringValue, int valueOffset=0)
 
size_t getTotalSize () const
 
size_t getDataSize () const
 
- Public Member Functions inherited from pcpp::TLVRecord< uint8_t, uint8_t >
 TLVRecord (uint8_t *recordRawData)
 
 TLVRecord (const TLVRecord &other)
 
virtual ~TLVRecord ()
 
void assign (uint8_t *recordRawData)
 
TLVRecordoperator= (const TLVRecord &other)
 
bool operator== (const TLVRecord &rhs) const
 
bool operator!= (const TLVRecord &rhs) const
 
uint8_t getType () const
 
uint8_t * getValue () const
 
bool isNull () const
 
bool isNotNull () const
 
uint8_t * getRecordBasePtr () const
 
void purgeRecordData ()
 
getValueAs (size_t offset=0) const
 
bool setValue (T newValue, int valueOffset=0)
 

Detailed Description

A wrapper class for DHCP options. This class does not create or modify DHCP option records, but rather serves as a wrapper and provides useful methods for setting and retrieving data to/from them

Constructor & Destructor Documentation

◆ DhcpOption()

pcpp::DhcpOption::DhcpOption ( uint8_t *  optionRawData)
inline

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

Parameters
[in]optionRawDataA pointer to the option raw data

◆ ~DhcpOption()

virtual pcpp::DhcpOption::~DhcpOption ( )
inlinevirtual

A d'tor for this class, currently does nothing

Member Function Documentation

◆ getDataSize()

size_t pcpp::DhcpOption::getDataSize ( ) const
inlinevirtual
Returns
The size of the record value (meaning the size of the 'V' part in TLV)

Implements pcpp::TLVRecord< uint8_t, uint8_t >.

◆ getTotalSize()

size_t pcpp::DhcpOption::getTotalSize ( ) const
inlinevirtual
Returns
The total size of the TLV record (in bytes)

Implements pcpp::TLVRecord< uint8_t, uint8_t >.

◆ getValueAsIpAddr()

IPv4Address pcpp::DhcpOption::getValueAsIpAddr ( ) const
inline

Retrieve DHCP option data as IPv4 address. Relevant only if option value is indeed an IPv4 address

Returns
DHCP option data as IPv4 address

◆ getValueAsString()

std::string pcpp::DhcpOption::getValueAsString ( int  valueOffset = 0) const
inline

Retrieve DHCP option data as string. Relevant only if option value is indeed a string

Parameters
[in]valueOffsetAn optional parameter that specifies where to start copy the DHCP option data. For example: when retrieving Client FQDN option, you may ignore the flags and RCODE fields using this method like this: getValueAsString(3). The default is 0 - start copying from the beginning of option data
Returns
DHCP option data as string

◆ setValueIpAddr()

void pcpp::DhcpOption::setValueIpAddr ( const IPv4Address addr,
int  valueOffset = 0 
)
inline

Set DHCP option data as IPv4 address. This method copies the 4 bytes of the IP address to the option value

Parameters
[in]addrThe IPv4 address to set
[in]valueOffsetAn optional parameter that specifies where to start set the option data (default set to 0). For example: if option data is 20 bytes long and you want to set the IP address in the 4 last bytes then use this method like this: setValueIpAddr(your_addr, 16)

◆ setValueString()

void pcpp::DhcpOption::setValueString ( const std::string &  stringValue,
int  valueOffset = 0 
)
inline

Set DHCP option data as string. This method copies the string to the option value. If the string is longer than option length the string is trimmed so it will fit the option length

Parameters
[in]stringValueThe string to set
[in]valueOffsetAn optional parameter that specifies where to start set the option data (default set to 0). For example: if option data is 20 bytes long and you want to set a 6 char-long string in the 6 last bytes then use this method like this: setValueString("string", 14)