PcapPlusPlus  22.11
pcpp::MxDnsResourceData Class Reference

#include <DnsResourceData.h>

Inheritance diagram for pcpp::MxDnsResourceData:
pcpp::IDnsResourceData

Classes

struct  MxData
 

Public Member Functions

 MxDnsResourceData (uint8_t *dataPtr, size_t dataLen, IDnsResource *dnsResource)
 
 MxDnsResourceData (const uint16_t &preference, const std::string &mailExchange)
 
bool operator== (const MxDnsResourceData &other) const
 
MxData getMxData () const
 
void setMxData (uint16_t preference, std::string mailExchange)
 
std::string toString () const
 
bool toByteArr (uint8_t *arr, size_t &arrLength, IDnsResource *dnsResource) const
 
- Public Member Functions inherited from pcpp::IDnsResourceData
virtual ~IDnsResourceData ()
 
template<class IDnsResourceDataType >
bool isTypeOf () const
 
template<class IDnsResourceDataType >
IDnsResourceDataType * castAs ()
 

Detailed Description

A class that represents DNS RR mail exchange (MX) data, used in DNS RRs of type DNS_TYPE_MX

Constructor & Destructor Documentation

◆ MxDnsResourceData() [1/2]

pcpp::MxDnsResourceData::MxDnsResourceData ( uint8_t *  dataPtr,
size_t  dataLen,
IDnsResource dnsResource 
)

A c'tor for this class

Parameters
[in]dataPtrA byte array that contains the raw MX data (as written in the DNS packet)
[in]dataLenThe byte array size
[in]dnsResourceA pointer to a DNS resource object where this DNS RR data will be stored

◆ MxDnsResourceData() [2/2]

pcpp::MxDnsResourceData::MxDnsResourceData ( const uint16_t &  preference,
const std::string &  mailExchange 
)

A c'tor for this class

Parameters
[in]preferenceThe MX preference value to store in this object
[in]mailExchangeThe MX hostname value to store in this object. It's possible to include a pointer to another string in the DNS layer (as explained here: http://www.zytrax.com/books/dns/ch15/#name). These pointers are often used to reduce the DNS packet size and avoid unnecessary duplications. The way to include pointers in the hostname string is to use the following format: 'some.domain.#{offset}' where '#{offset}' is the offset from the start of the DNS layer. For example: if the string 'yahoo.com' already appears in offset 12 in the packet and you want to set the DNS RR data as 'my.subdomain.yahoo.com' you may use the following string: 'my.subdomain.#12'. This will result in writing 'my.subdomain' and a pointer to offset 12

Member Function Documentation

◆ getMxData()

MxData pcpp::MxDnsResourceData::getMxData ( ) const
inline
Returns
The MX data stored in this object

◆ operator==()

bool pcpp::MxDnsResourceData::operator== ( const MxDnsResourceData other) const

Equality operator overload for this class that compares the MX data stored in each object

Parameters
[in]otherThe object to compare with
Returns
True if MX data is the same in both objects, meaning both preference and MX hostname are the same, false otherwise

◆ setMxData()

void pcpp::MxDnsResourceData::setMxData ( uint16_t  preference,
std::string  mailExchange 
)

Set the MX data stored in this object

Parameters
[in]preferenceThe MX preference value to store in this object
[in]mailExchangeThe MX hostname value to store in this object

◆ toByteArr()

bool pcpp::MxDnsResourceData::toByteArr ( uint8_t *  arr,
size_t &  arrLength,
IDnsResource dnsResource 
) const
virtual

Convert the DNS RR data into a byte array

Parameters
[out]arrA pointer to a pre-allocated byte array where the result will be written to
[out]arrLengthA reference to a 2-byte number where the result array length will be written to
[in]dnsResourceA pointer to a DNS resource object where this DNS RR data will be stored
Returns
True if the DNS RR data was successfully converted into a byte array and written to the given array or false if stored DNS RR data is invalid or if it could not be written to the given array

Implements pcpp::IDnsResourceData.

◆ toString()

std::string pcpp::MxDnsResourceData::toString ( ) const
virtual

A string representation of the MX data stored in this object. The string format is as follows: 'pref: {preference_value}; mx: {mail_exchange_hostname_value}'

Implements pcpp::IDnsResourceData.