22 #if (BYTE_ORDER == LITTLE_ENDIAN)
44 #elif (BYTE_ORDER == BIG_ENDIAN)
77 static_assert(
sizeof(
dnshdr) == 12,
"dnshdr size is not 12 bytes");
162 bool removeQuery(
const std::string& queryNameToRemove,
bool exactMatch);
215 bool removeAnswer(
const std::string& answerNameToRemove,
bool exactMatch);
377 static inline bool isDnsPort(uint16_t port);
385 static inline bool isDataValid(
const uint8_t* data,
size_t dataLen,
bool dnsOverTcp =
false);
388 DnsLayer(uint8_t* data,
size_t dataLen,
Layer* prevLayer,
Packet* packet,
size_t offsetAdjustment);
389 explicit DnsLayer(
size_t offsetAdjustment);
397 uint16_t m_OffsetAdjustment;
399 size_t getBasicHeaderSize();
400 void init(
size_t offsetAdjustment,
bool callParseResource);
401 void initNewLayer(
size_t offsetAdjustment);
406 using Layer::extendLayer;
407 bool extendLayer(
int offsetInLayer,
size_t numOfBytesToExtend,
IDnsResource* resource);
409 using Layer::shortenLayer;
410 bool shortenLayer(
int offsetInLayer,
size_t numOfBytesToShorten,
IDnsResource* resource);
413 bool exactMatch)
const;
415 void parseResources();
440 :
DnsLayer(data, dataLen, prevLayer, packet, sizeof(uint16_t))
483 size_t minSize =
sizeof(
dnshdr) + (dnsOverTcp ?
sizeof(uint16_t) : 0);
484 return data && dataLen >= minSize;
Definition: DnsLayer.h:88
DnsResource * getFirstAnswer() const
DnsLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
DnsResource * addAdditionalRecord(const std::string &name, DnsType dnsType, DnsClass dnsClass, uint32_t ttl, IDnsResourceData *data)
size_t getHeaderLen() const override
Definition: DnsLayer.h:358
DnsQuery * getQuery(const std::string &name, bool exactMatch) const
DnsResource * addAdditionalRecord(const std::string &name, DnsType dnsType, uint16_t customData1, uint32_t customData2, IDnsResourceData *data)
DnsResource * addAuthority(DnsResource *const copyAuthority)
static bool isDataValid(const uint8_t *data, size_t dataLen, bool dnsOverTcp=false)
Definition: DnsLayer.h:481
DnsQuery * addQuery(DnsQuery *const copyQuery)
DnsResource * getAuthority(const std::string &name, bool exactMatch) const
bool removeAdditionalRecord(DnsResource *additionalRecordToRemove)
DnsResource * addAdditionalRecord(DnsResource *const copyAdditionalRecord)
DnsResource * addAnswer(DnsResource *const copyAnswer)
bool removeQuery(const std::string &queryNameToRemove, bool exactMatch)
DnsResource * getAdditionalRecord(const std::string &name, bool exactMatch) const
size_t getQueryCount() const
DnsResource * getNextAuthority(DnsResource *authority) const
std::string toString() const override
DnsResource * getNextAnswer(DnsResource *answer) const
void computeCalculateFields() override
Does nothing for this layer.
Definition: DnsLayer.h:364
DnsQuery * addQuery(const std::string &name, DnsType dnsType, DnsClass dnsClass)
DnsLayer(const DnsLayer &other)
DnsQuery * getNextQuery(DnsQuery *query) const
DnsResource * getFirstAdditionalRecord() const
bool removeAuthority(const std::string &authorityNameToRemove, bool exactMatch)
DnsResource * getFirstAuthority() const
bool removeQuery(DnsQuery *queryToRemove)
size_t getAuthorityCount() const
size_t getAnswerCount() const
dnshdr * getDnsHeader() const
void parseNextLayer() override
Does nothing for this layer (DnsLayer is always last)
Definition: DnsLayer.h:353
DnsResource * addAuthority(const std::string &name, DnsType dnsType, DnsClass dnsClass, uint32_t ttl, IDnsResourceData *data)
bool removeAnswer(DnsResource *answerToRemove)
DnsResource * getNextAdditionalRecord(DnsResource *additionalRecord) const
DnsQuery * getFirstQuery() const
DnsResource * addAnswer(const std::string &name, DnsType dnsType, DnsClass dnsClass, uint32_t ttl, IDnsResourceData *data)
bool removeAdditionalRecord(const std::string &additionalRecordNameToRemove, bool exactMatch)
bool removeAnswer(const std::string &answerNameToRemove, bool exactMatch)
static bool isDnsPort(uint16_t port)
Definition: DnsLayer.h:468
DnsLayer & operator=(const DnsLayer &other)
bool removeAuthority(DnsResource *authorityToRemove)
OsiModelLayer getOsiModelLayer() const override
Definition: DnsLayer.h:369
size_t getAdditionalRecordCount() const
DnsResource * getAnswer(const std::string &name, bool exactMatch) const
Definition: DnsLayer.h:432
DnsOverTcpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: DnsLayer.h:439
void computeCalculateFields() override
Calculate the TCP message length field.
void setTcpMessageLength(uint16_t value)
uint16_t getTcpMessageLength()
DnsOverTcpLayer()
Definition: DnsLayer.h:445
DnsOverTcpLayer(const DnsOverTcpLayer &other)
Definition: DnsLayer.h:450
Definition: DnsResource.h:113
Definition: DnsResource.h:140
Definition: DnsResourceData.h:24
Definition: DnsResource.h:26
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
An enum representing OSI model layers.
Definition: ProtocolType.h:225
@ OsiModelApplicationLayer
Application layer (layer 7)
Definition: ProtocolType.h:239
DnsClass
An enum for all possible DNS classes.
Definition: DnsLayerEnums.h:120
DnsResourceType
An enum for representing the 4 types of possible DNS records.
Definition: DnsLayerEnums.h:135
DnsType
An enum for all possible DNS record types.
Definition: DnsLayerEnums.h:11
Definition: DnsLayer.h:19
uint16_t responseCode
Return Code.
Definition: DnsLayer.h:35
uint16_t authoritativeAnswer
Authoritative answer flag.
Definition: DnsLayer.h:29
uint16_t queryOrResponse
Query/Response flag.
Definition: DnsLayer.h:33
uint16_t zero
Zero flag (Reserved)
Definition: DnsLayer.h:41
uint16_t transactionID
DNS query identification.
Definition: DnsLayer.h:21
uint16_t numberOfAuthority
Number of authority records in packet.
Definition: DnsLayer.h:72
uint16_t truncation
Truncated flag.
Definition: DnsLayer.h:27
uint16_t numberOfAdditional
Number of additional records in packet.
Definition: DnsLayer.h:74
uint16_t checkingDisabled
Checking disabled flag.
Definition: DnsLayer.h:37
uint16_t numberOfAnswers
Number of DNS answer records in packet.
Definition: DnsLayer.h:70
uint16_t authenticData
Authenticated data flag.
Definition: DnsLayer.h:39
uint16_t opcode
Operation Code.
Definition: DnsLayer.h:31
uint16_t recursionAvailable
Recursion available flag.
Definition: DnsLayer.h:43
uint16_t recursionDesired
Recursion desired flag.
Definition: DnsLayer.h:25
uint16_t numberOfQuestions
Number of DNS query records in packet.
Definition: DnsLayer.h:68