PcapPlusPlus
pcpp::DnsResource Class Reference

#include <DnsLayer.h>

Inheritance diagram for pcpp::DnsResource:
pcpp::IDnsResource

Public Member Functions

uint32_t getTTL ()
 
void setTTL (uint32_t newTTL)
 
size_t getDataLength ()
 
std::string getDataAsString ()
 
bool setData (const std::string &dataAsString)
 
uint16_t getCustomDnsClass ()
 
void setCustomDnsClass (uint16_t customValue)
 
virtual size_t getSize ()
 
virtual ResourceType getType ()
 
- Public Member Functions inherited from pcpp::IDnsResource
DnsType getDnsType ()
 
void setDnsType (DnsType newType)
 
DnsClass getDnsClass ()
 
void setDnsClass (DnsClass newClass)
 
std::string getName ()
 
bool setName (const std::string &newName)
 

Additional Inherited Members

- Public Types inherited from pcpp::IDnsResource
enum  ResourceType { DnsQuery = 0, DnsAnswer = 1, DnsAuthority = 2, DnsAdditional = 3 }
 

Detailed Description

Representing DNS record other than DNS query

Member Function Documentation

◆ getCustomDnsClass()

uint16_t pcpp::DnsResource::getCustomDnsClass ( )

Some records don't have a DNS class and the bytes used for storing the DNS class are used for other purpose. This method enables the user to receive these bytes

Returns
The value stored in this place

◆ getDataAsString()

std::string pcpp::DnsResource::getDataAsString ( )
Returns
The record data as string. The return value depends on the DNS type of this record:

◆ getDataLength()

size_t pcpp::DnsResource::getDataLength ( )
Returns
The data length value for this record (taken from the "data length" field of the record)

◆ getSize()

virtual size_t pcpp::DnsResource::getSize ( )
inlinevirtual
Returns
The total size in bytes of this record

Implements pcpp::IDnsResource.

◆ getTTL()

uint32_t pcpp::DnsResource::getTTL ( )
Returns
The time-to-leave value for this record

◆ getType()

virtual ResourceType pcpp::DnsResource::getType ( )
inlinevirtual
Returns
The type of this record (query, answer, authority, additional)

Implements pcpp::IDnsResource.

◆ setCustomDnsClass()

void pcpp::DnsResource::setCustomDnsClass ( uint16_t  customValue)

Some records don't have a DNS class and the bytes used for storing the DNS class are used for other purpose. This method enables the user to set these bytes

Parameters
[in]customValueThe value to set

◆ setData()

bool pcpp::DnsResource::setData ( const std::string &  dataAsString)

Set resource data. Data is parse from string and is validated against the DNS type of the resource. For example: if DNS type is A and data isn't a valid IPv4 address a log error will be printed and the method will return false. This method currently supports the following DNS types:

  • DNS_TYPE_A (IPv4 address) - data is expected to be a valid IPv4 address
  • DNS_TYPE_AAAA (IPv6 address) - data is expected to be a valid IPv6 address
  • DNS_TYPE_NS, DNS_TYPE_CNAME, DNS_TYPE_DNAM, DNS_TYPE_PTR, DNS_TYPE_MX (name data) - data is expected to be a valid host name, e.g: 'www.google.com'
  • else: data is expected to be a valid hex string which starts with '0x' followed by the an even number of characters representing a valid hex data. e.g: '0x0d0a45569a9b'
    Parameters
    [in]dataAsStringThe string representation of the relevant data
    Returns
    True if data was properly set or false if data is illegal or method couldn't extend or shorted the packet (appropriate error log is printed in all cases)

◆ setTTL()

void pcpp::DnsResource::setTTL ( uint32_t  newTTL)

Set time-to-leave value for this record

Parameters
[in]newTTLThe new TTL value to set