PcapPlusPlus
|
#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 () |
DnsQuery * | getQuery (const std::string &name, bool exactMatch) |
DnsQuery * | getFirstQuery () |
DnsQuery * | getNextQuery (DnsQuery *query) |
size_t | getQueryCount () |
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) |
DnsResource * | getFirstAnswer () |
DnsResource * | getNextAnswer (DnsResource *answer) |
size_t | getAnswerCount () |
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) |
DnsResource * | getFirstAuthority () |
DnsResource * | getNextAuthority (DnsResource *authority) |
size_t | getAuthorityCount () |
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) |
DnsResource * | getFirstAdditionalRecord () |
DnsResource * | getNextAdditionalRecord (DnsResource *additionalRecord) |
size_t | getAdditionalRecordCount () |
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 () |
void | computeCalculateFields () |
std::string | toString () |
OsiModelLayer | getOsiModelLayer () |
Public Member Functions inherited from pcpp::Layer | |
virtual | ~Layer () |
Layer * | getNextLayer () |
Layer * | getPrevLayer () |
ProtocolType | getProtocol () |
uint8_t * | getData () |
size_t | getDataLen () |
uint8_t * | getLayerPayload () |
size_t | getLayerPayloadSize () |
bool | isAllocatedToPacket () |
void | copyData (uint8_t *toArr) |
uint8_t * | getDataPtr (size_t offset=0) |
Static Public Member Functions | |
static const std::map< uint16_t, bool > * | getDNSPortMap () |
Represents the DNS protocol layer.
CURRENTLY ONLY DNS PARSING IS AVAILABLE. CREATING AND EDITING DNS ATTRIBUTES WILL BE ADDED LATER
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 |
Does nothing for this layer
Implements pcpp::Layer.
DnsResource* pcpp::DnsLayer::getAdditionalRecord | ( | const std::string & | name, |
bool | exactMatch | ||
) |
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 | ( | ) |
DnsResource* pcpp::DnsLayer::getAnswer | ( | const std::string & | name, |
bool | exactMatch | ||
) |
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 | ( | ) |
DnsResource* pcpp::DnsLayer::getAuthority | ( | const std::string & | name, |
bool | exactMatch | ||
) |
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 | ( | ) |
|
inline |
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
|
static |
DnsResource* pcpp::DnsLayer::getFirstAdditionalRecord | ( | ) |
DnsResource* pcpp::DnsLayer::getFirstAnswer | ( | ) |
DnsResource* pcpp::DnsLayer::getFirstAuthority | ( | ) |
DnsQuery* pcpp::DnsLayer::getFirstQuery | ( | ) |
|
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 | ) |
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 | ) |
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 | ) |
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 | ||
) |
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 | ( | ) |
|
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.