PcapPlusPlus
21.05
|
#include <DnsLayer.h>
Public Member Functions | |
DnsLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) | |
DnsLayer () | |
DnsLayer (const DnsLayer &other) | |
DnsLayer & | operator= (const DnsLayer &other) |
dnshdr * | getDnsHeader () const |
DnsQuery * | getQuery (const std::string &name, bool exactMatch) const |
DnsQuery * | getFirstQuery () const |
DnsQuery * | getNextQuery (DnsQuery *query) const |
size_t | getQueryCount () const |
DnsQuery * | addQuery (const std::string &name, DnsType dnsType, DnsClass dnsClass) |
DnsQuery * | addQuery (DnsQuery *const copyQuery) |
bool | removeQuery (const std::string &queryNameToRemove, bool exactMatch) |
bool | removeQuery (DnsQuery *queryToRemove) |
DnsResource * | getAnswer (const std::string &name, bool exactMatch) const |
DnsResource * | getFirstAnswer () const |
DnsResource * | getNextAnswer (DnsResource *answer) const |
size_t | getAnswerCount () const |
DnsResource * | addAnswer (const std::string &name, DnsType dnsType, DnsClass dnsClass, uint32_t ttl, IDnsResourceData *data) |
DnsResource * | addAnswer (DnsResource *const copyAnswer) |
bool | removeAnswer (const std::string &answerNameToRemove, bool exactMatch) |
bool | removeAnswer (DnsResource *answerToRemove) |
DnsResource * | getAuthority (const std::string &name, bool exactMatch) const |
DnsResource * | getFirstAuthority () const |
DnsResource * | getNextAuthority (DnsResource *authority) const |
size_t | getAuthorityCount () const |
DnsResource * | addAuthority (const std::string &name, DnsType dnsType, DnsClass dnsClass, uint32_t ttl, IDnsResourceData *data) |
DnsResource * | addAuthority (DnsResource *const copyAuthority) |
bool | removeAuthority (const std::string &authorityNameToRemove, bool exactMatch) |
bool | removeAuthority (DnsResource *authorityToRemove) |
DnsResource * | getAdditionalRecord (const std::string &name, bool exactMatch) const |
DnsResource * | getFirstAdditionalRecord () const |
DnsResource * | getNextAdditionalRecord (DnsResource *additionalRecord) const |
size_t | getAdditionalRecordCount () const |
DnsResource * | addAdditionalRecord (const std::string &name, DnsType dnsType, DnsClass dnsClass, uint32_t ttl, IDnsResourceData *data) |
DnsResource * | addAdditionalRecord (const std::string &name, DnsType dnsType, uint16_t customData1, uint32_t customData2, IDnsResourceData *data) |
DnsResource * | addAdditionalRecord (DnsResource *const copyAdditionalRecord) |
bool | removeAdditionalRecord (const std::string &additionalRecordNameToRemove, bool exactMatch) |
bool | removeAdditionalRecord (DnsResource *additionalRecordToRemove) |
void | parseNextLayer () |
size_t | getHeaderLen () const |
virtual void | computeCalculateFields () |
std::string | toString () const |
OsiModelLayer | getOsiModelLayer () const |
Public Member Functions inherited from pcpp::Layer | |
virtual | ~Layer () |
Layer * | getNextLayer () const |
Layer * | getPrevLayer () const |
ProtocolType | getProtocol () const |
uint8_t * | getData () const |
size_t | getDataLen () const |
uint8_t * | getLayerPayload () const |
size_t | getLayerPayloadSize () const |
bool | isAllocatedToPacket () const |
void | copyData (uint8_t *toArr) const |
uint8_t * | getDataPtr (size_t offset=0) const |
Static Public Member Functions | |
static bool | isDnsPort (uint16_t port) |
static bool | isDataValid (const uint8_t *data, size_t dataLen, bool dnsOverTcp=false) |
Represents the DNS protocol layer
A constructor that creates the layer from an existing packet raw data
[in] | data | A pointer to the raw data |
[in] | dataLen | Size of the data in bytes |
[in] | prevLayer | A pointer to the previous layer |
[in] | packet | A pointer to the Packet instance where layer will be stored in |
pcpp::DnsLayer::DnsLayer | ( | ) |
A constructor that creates an empty DNS layer: all members of dnshdr are set to 0 and layer will contain no records
pcpp::DnsLayer::DnsLayer | ( | const DnsLayer & | other | ) |
A copy constructor for this layer
DnsResource* pcpp::DnsLayer::addAdditionalRecord | ( | const std::string & | name, |
DnsType | dnsType, | ||
DnsClass | dnsClass, | ||
uint32_t | ttl, | ||
IDnsResourceData * | data | ||
) |
Add a new DNS additional record to the layer
[in] | name | The value that shall be set in the name field of the additional record |
[in] | dnsType | The value that shall be set in the DNS type field of the additional record |
[in] | dnsClass | The value that shall be set in the DNS class field of the additional record |
[in] | ttl | The value that shall be set in the 'time-to-leave' field of the additional record |
[in] | data | The additional record data to be set. The type of the data should match the type of the DNS record (for example: DNS record of type A should have data of type IPv4DnsResourceData. Please see DnsResource::setData() for more info on this |
DnsResource* pcpp::DnsLayer::addAdditionalRecord | ( | const std::string & | name, |
DnsType | dnsType, | ||
uint16_t | customData1, | ||
uint32_t | customData2, | ||
IDnsResourceData * | data | ||
) |
Add a new DNS additional record to the layer that doesn't have DNS class and TTL. Instead these bytes may contains some arbitrary data. In the future I may add support for these kinds of additional data records. For now, these bytes are set as raw
[in] | name | The value that shall be set in the name field of the additional record |
[in] | dnsType | The value that shall be set in the DNS type field of the additional record |
[in] | customData1 | Two bytes of the arbitrary data that will be set in the offset usually used for the DNS class |
[in] | customData2 | Four bytes of the arbitrary data that will be set in the offset usually used for the TTL |
[in] | data | The additional record data to be set. The type of the data should match the type of the DNS record. (for example: DNS record of type A should have data of type IPv4DnsResourceData. Please see DnsResource::setData() for more info on this |
DnsResource* pcpp::DnsLayer::addAdditionalRecord | ( | DnsResource *const | copyAdditionalRecord | ) |
Add a new DNS additional record similar to an already existing DNS additional record. All additional record fields will be copied from the existing additional record param[in] copyAdditionalRecord The record to create the new record from. copyAdditionalRecord won't be changed in any way
DnsResource* pcpp::DnsLayer::addAnswer | ( | const std::string & | name, |
DnsType | dnsType, | ||
DnsClass | dnsClass, | ||
uint32_t | ttl, | ||
IDnsResourceData * | data | ||
) |
Add a new DNS answer to the layer
[in] | name | The value that shall be set in the name field of the answer |
[in] | dnsType | The value that shall be set in the DNS type field of the answer |
[in] | dnsClass | The value that shall be set in the DNS class field of the answer |
[in] | ttl | The value that shall be set in the 'time-to-leave' field of the answer |
[in] | data | The answer data to be set. The type of the data should match the type of the DNS record (for example: DNS record of type A should have data of type IPv4DnsResourceData. Please see DnsResource::setData() for more info on this |
DnsResource* pcpp::DnsLayer::addAnswer | ( | DnsResource *const | copyAnswer | ) |
Add a new DNS answer similar to an already existing DNS answer. All answer fields will be copied from the existing answer param[in] copyAnswer The record to create the new record from. copyAnswer won't be changed in any way
DnsResource* pcpp::DnsLayer::addAuthority | ( | const std::string & | name, |
DnsType | dnsType, | ||
DnsClass | dnsClass, | ||
uint32_t | ttl, | ||
IDnsResourceData * | data | ||
) |
Add a new DNS authority to the layer
[in] | name | The value that shall be set in the name field of the authority |
[in] | dnsType | The value that shall be set in the DNS type field of the authority |
[in] | dnsClass | The value that shall be set in the DNS class field of the authority |
[in] | ttl | The value that shall be set in the 'time-to-leave' field of the authority |
[in] | data | The authority data to be set. The type of the data should match the type of the DNS record (for example: DNS record of type A should have data of type IPv4DnsResourceData. Please see DnsResource::setData() for more info on this |
DnsResource* pcpp::DnsLayer::addAuthority | ( | DnsResource *const | copyAuthority | ) |
Add a new DNS authority similar to an already existing DNS authority. All authority fields will be copied from the existing authority param[in] copyAuthority The record to create the new record from. copyAuthority won't be changed in any way
Add a new DNS query to the layer
[in] | name | The value that shall be set in the name field of the query |
[in] | dnsType | The value that shall be set in the DNS type field of the query |
[in] | dnsClass | The value that shall be set in the DNS class field of the query |
Add a new DNS query similar to an already existing DNS query. All query fields will be copied from the existing query param[in] copyQuery The record to create the new record from. copyQuery won't be changed in any way
|
inlinevirtual |
DnsResource* pcpp::DnsLayer::getAdditionalRecord | ( | const std::string & | name, |
bool | exactMatch | ||
) | const |
Searches for a DNS additional record by its name field. Notice this method returns only an additional record which its name equals to the requested name. If several additional records match the requested name, the first one will be returned. If no additional records match the requested name, NULL will be returned
[in] | name | The name of the additional record to search |
[in] | exactMatch | Indicate whether to match the whole name or just a part of it |
size_t pcpp::DnsLayer::getAdditionalRecordCount | ( | ) | const |
DnsResource* pcpp::DnsLayer::getAnswer | ( | const std::string & | name, |
bool | exactMatch | ||
) | const |
Searches for a DNS answer by its name field. Notice this method returns only an answer which its name equals to the requested name. If several answers match the requested name, the first one will be returned. If no answers match the requested name, NULL will be returned
[in] | name | The name of the answer to search |
[in] | exactMatch | Indicate whether to match the whole name or just a part of it |
size_t pcpp::DnsLayer::getAnswerCount | ( | ) | const |
DnsResource* pcpp::DnsLayer::getAuthority | ( | const std::string & | name, |
bool | exactMatch | ||
) | const |
Searches for a DNS authority by its name field. Notice this method returns only an authority which its name equals to the requested name. If several authorities match the requested name, the first one will be returned. If no authorities match the requested name, NULL will be returned
[in] | name | The name of the authority to search |
[in] | exactMatch | Indicate whether to match the whole name or just a part of it |
size_t pcpp::DnsLayer::getAuthorityCount | ( | ) | const |
dnshdr* pcpp::DnsLayer::getDnsHeader | ( | ) | const |
Get a pointer to the DNS header (as opposed to the DNS data which is the queries, answers, etc. Data can be retrieved through the other methods of this layer. Notice the return value points directly to the data, so every change will change the actual packet data
DnsResource* pcpp::DnsLayer::getFirstAdditionalRecord | ( | ) | const |
DnsResource* pcpp::DnsLayer::getFirstAnswer | ( | ) | const |
DnsResource* pcpp::DnsLayer::getFirstAuthority | ( | ) | const |
DnsQuery* pcpp::DnsLayer::getFirstQuery | ( | ) | const |
|
inlinevirtual |
Return the size of the DNS data in the packet including he DNS header and size of all queries, answers, authorities and additional records
Implements pcpp::Layer.
DnsResource* pcpp::DnsLayer::getNextAdditionalRecord | ( | DnsResource * | additionalRecord | ) | const |
Get the DNS additional record following a certain additional record
[in] | additionalRecord | A pointer to a DNS additional record that exist in the packet |
DnsResource* pcpp::DnsLayer::getNextAnswer | ( | DnsResource * | answer | ) | const |
Get the DNS answer following a certain answer
[in] | answer | A pointer to a DNS answer that exist in the packet |
DnsResource* pcpp::DnsLayer::getNextAuthority | ( | DnsResource * | authority | ) | const |
Get the DNS authority following a certain authority
[in] | authority | A pointer to a DNS authority that exist in the packet |
Get the DNS query following a certain query
[in] | query | A pointer to a DNS query that exist in the packet |
|
inlinevirtual |
Implements pcpp::Layer.
DnsQuery* pcpp::DnsLayer::getQuery | ( | const std::string & | name, |
bool | exactMatch | ||
) | const |
Searches for a DNS query by its name field. Notice this method returns only a query which its name equals to the requested name. If several queries match the requested name, the first one will be returned. If no queries match the requested name, NULL will be returned
[in] | name | The name of the query to search |
[in] | exactMatch | Indicate whether to match the whole name or just a part of it |
size_t pcpp::DnsLayer::getQueryCount | ( | ) | const |
|
inlinestatic |
A static method that validates the input data
[in] | data | The pointer to the beginning of a byte stream of a DNS packet |
[in] | dataLen | The length of the byte stream |
[in] | dnsOverTcp | Should be set to "true" if this is DNS is over TCP, otherwise set to "false" (which is also the default value) |
|
inlinestatic |
A static method that checks whether the port is considered as DNS
[in] | port | The port number to be checked |
|
inlinevirtual |
Does nothing for this layer (DnsLayer is always last)
Implements pcpp::Layer.
bool pcpp::DnsLayer::removeAdditionalRecord | ( | const std::string & | additionalRecordNameToRemove, |
bool | exactMatch | ||
) |
Remove an existing additional record by name. If several additional records matches the name, the first match will be removed
[in] | additionalRecordNameToRemove | The name of the additional record to remove |
[in] | exactMatch | Indicate whether to match the whole name or just a part of it |
bool pcpp::DnsLayer::removeAdditionalRecord | ( | DnsResource * | additionalRecordToRemove | ) |
Remove an existing additional record
[in] | additionalRecordToRemove | A pointer to the additional record to remove |
bool pcpp::DnsLayer::removeAnswer | ( | const std::string & | answerNameToRemove, |
bool | exactMatch | ||
) |
Remove an existing answer by name. If several answers matches the name, the first match will be removed
[in] | answerNameToRemove | The name of the answer to remove |
[in] | exactMatch | Indicate whether to match the whole name or just a part of it |
bool pcpp::DnsLayer::removeAnswer | ( | DnsResource * | answerToRemove | ) |
Remove an existing answer
[in] | answerToRemove | A pointer to the answer to remove |
bool pcpp::DnsLayer::removeAuthority | ( | const std::string & | authorityNameToRemove, |
bool | exactMatch | ||
) |
Remove an existing authority by name. If several authorities matches the name, the first match will be removed
[in] | authorityNameToRemove | The name of the authority to remove |
[in] | exactMatch | Indicate whether to match the whole name or just a part of it |
bool pcpp::DnsLayer::removeAuthority | ( | DnsResource * | authorityToRemove | ) |
Remove an existing authority
[in] | authorityToRemove | A pointer to the authority to remove |
bool pcpp::DnsLayer::removeQuery | ( | const std::string & | queryNameToRemove, |
bool | exactMatch | ||
) |
Remove an existing query by name. If several queries matches the name, the first match will be removed
[in] | queryNameToRemove | The name of the query to remove |
[in] | exactMatch | Indicate whether to match the whole name or just a part of it |
bool pcpp::DnsLayer::removeQuery | ( | DnsQuery * | queryToRemove | ) |
Remove an existing query
[in] | queryToRemove | A pointer to the query to remove |
|
virtual |
Implements pcpp::Layer.