PcapPlusPlus
pcpp::DhcpOptionData Struct Reference

#include <DhcpLayer.h>

Public Member Functions

template<typename T >
getValueAs (int valueOffset=0)
 
IPv4Address getValueAsIpAddr ()
 
std::string getValueAsString (int valueOffset=0)
 
template<typename T >
void setValue (T newValue, int valueOffset=0)
 
void setValueIpAddr (const IPv4Address &addr, int valueOffset=0)
 
void setValueString (const std::string &stringValue, int valueOffset=0)
 
size_t getTotalSize () const
 
uint8_t getLength ()
 
DhcpOptionTypes getType ()
 

Public Attributes

uint8_t opCode
 
uint8_t len
 
uint8_t value []
 

Detailed Description

Representing a DHCP option in a TLV (type-length-value) structure

Member Function Documentation

◆ getLength()

uint8_t pcpp::DhcpOptionData::getLength ( )
inline
Returns
The length of the option value

◆ getTotalSize()

size_t pcpp::DhcpOptionData::getTotalSize ( ) const
inline
Returns
The total size in bytes of this DHCP option which includes: 1[Byte] (option type) + 1[Byte] (option length) + X[Bytes] (option data length). For DHCPOPT_END and DHCPOPT_PAD the value 1 is returned

◆ getType()

DhcpOptionTypes pcpp::DhcpOptionData::getType ( )
inline
Returns
DHCP option type casted as pcpp::DhcpOptionTypes enum

◆ getValueAs()

template<typename T >
T pcpp::DhcpOptionData::getValueAs ( int  valueOffset = 0)
inline

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

Parameters
[in]valueOffsetAn optional parameter that specifies where to start copy the DHCP option data. For example: if option data is 20 bytes and you need only the 4 last bytes as integer then use this method like this: getValueAs<int>(16). The default is 0 - start copying from the beginning of option data
Returns
The DHCP option data as type T

◆ getValueAsIpAddr()

IPv4Address pcpp::DhcpOptionData::getValueAsIpAddr ( )
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::DhcpOptionData::getValueAsString ( int  valueOffset = 0)
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

◆ setValue()

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

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

Parameters
[in]newValueThe value of type T to copy to DHCP option data
[in]valueOffsetAn optional parameter that specifies where to start setting the option data (default set to 0). For example: if option 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)

◆ setValueIpAddr()

void pcpp::DhcpOptionData::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::DhcpOptionData::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)

Member Data Documentation

◆ len

uint8_t pcpp::DhcpOptionData::len

DHCP option length

◆ opCode

uint8_t pcpp::DhcpOptionData::opCode

DHCP option code, should be on of DhcpOptionTypes

◆ value

uint8_t pcpp::DhcpOptionData::value[]

DHCP option value