PcapPlusPlus  21.05
pcpp::DnsResource Class Reference

#include <DnsResource.h>

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

Public Member Functions

uint32_t getTTL () const
 
void setTTL (uint32_t newTTL)
 
size_t getDataLength () const
 
DnsResourceDataPtr getData () const
 
size_t getDataOffset () const
 
bool setData (IDnsResourceData *data)
 
uint16_t getCustomDnsClass () const
 
void setCustomDnsClass (uint16_t customValue)
 
virtual size_t getSize () const
 
virtual DnsResourceType getType () const
 
- Public Member Functions inherited from pcpp::IDnsResource
DnsType getDnsType () const
 
void setDnsType (DnsType newType)
 
DnsClass getDnsClass () const
 
void setDnsClass (DnsClass newClass)
 
const std::string & getName () const
 
size_t getNameOffset () const
 
bool setName (const std::string &newName)
 

Detailed Description

Representing DNS record other than DNS query

Member Function Documentation

◆ getCustomDnsClass()

uint16_t pcpp::DnsResource::getCustomDnsClass ( ) const

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

◆ getData()

DnsResourceDataPtr pcpp::DnsResource::getData ( ) const
Returns
A smart pointer to an IDnsResourceData object that contains the DNS resource data. It is guaranteed that the smart pointer will always point to an object and never to NULL. The specific object type depends on the DNS type of this record:

◆ getDataLength()

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

◆ getDataOffset()

size_t pcpp::DnsResource::getDataOffset ( ) const
Returns
The offset of data in the DNS layer

◆ getSize()

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

Implements pcpp::IDnsResource.

◆ getTTL()

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

◆ getType()

virtual DnsResourceType pcpp::DnsResource::getType ( ) const
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 ( IDnsResourceData data)

Set resource data. The given IDnsResourceData input object is validated against the DNS type of the resource. For example: if DNS type is A and data isn't of type IPv4DnsResourceData (which contains the 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 pointer to IPv4DnsResourceData with a valid IPv4 address
  • DNS_TYPE_AAAA (IPv6 address) - data is expected to be a pointer to IPv6DnsResourceData with a valid IPv6 address
  • DNS_TYPE_NS, DNS_TYPE_CNAME, DNS_TYPE_DNAM, DNS_TYPE_PTR (name data) - data is expected to be a pointer to StringDnsResourceData object that contains a host name, e.g: 'www.google.com'
  • DNS_TYPE_MX (MX data) - data is expected to be a pointer to MxDnsResourceData object that contains the MX data
  • else: data is expected to be a pointer to GenericDnsResourceData object that contains a valid hex string (valid hex string means a string which has an even number of characters representing a valid hex data. e.g: '0d0a45569a9b')
    Parameters
    [in]dataThe pointer to the data object, as described above
    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