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);
392 static std::vector<FieldDescriptor>
all()
400 std::copy(extra.begin(), extra.end(), std::back_inserter(result));
411 static std::vector<FieldDescriptor>
all()
437 static std::vector<FieldDescriptor>
all()
516 DnsLayer(uint8_t* data,
size_t dataLen,
Layer* prevLayer,
Packet* packet,
size_t offsetAdjustment);
517 explicit DnsLayer(
size_t offsetAdjustment);
527 uint16_t m_OffsetAdjustment;
529 size_t getBasicHeaderSize();
530 void init(
size_t offsetAdjustment,
bool callParseResource);
531 void initNewLayer(
size_t offsetAdjustment);
536 using Layer::extendLayer;
537 bool extendLayer(
int offsetInLayer,
size_t numOfBytesToExtend,
IDnsResource* resource);
539 using Layer::shortenLayer;
540 bool shortenLayer(
int offsetInLayer,
size_t numOfBytesToShorten,
IDnsResource* resource);
543 bool exactMatch)
const;
545 void parseResources();
570 :
DnsLayer(data, dataLen, prevLayer, packet, sizeof(uint16_t))
601 static std::vector<FieldDescriptor>
all()
633 size_t minSize =
sizeof(
dnshdr) + (dnsOverTcp ?
sizeof(uint16_t) : 0);
634 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:631
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
void serializeLayer(ObjectScope &serializer) const override
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:618
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:562
DnsOverTcpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: DnsLayer.h:569
void computeCalculateFields() override
Calculate the TCP message length field.
void serializeLayer(ObjectScope &serializer) const override
void setTcpMessageLength(uint16_t value)
uint16_t getTcpMessageLength()
DnsOverTcpLayer()
Definition: DnsLayer.h:575
DnsOverTcpLayer(const DnsOverTcpLayer &other)
Definition: DnsLayer.h:580
Definition: DnsResource.h:113
Definition: DnsResource.h:140
Definition: DnsResourceData.h:26
Definition: DnsResource.h:26
Definition: Serializers.h:230
The main namespace for the PcapPlusPlus lib.
Definition: AssertionUtils.h:19
OsiModelLayer
An enum representing OSI model layers.
Definition: ProtocolType.h:430
@ OsiModelApplicationLayer
Application layer (layer 7)
Definition: ProtocolType.h:446
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:407
static std::vector< FieldDescriptor > all()
Definition: DnsLayer.h:411
static const FieldDescriptor Name
Field descriptor for the queried name, written as a string.
Definition: DnsLayer.h:417
static const FieldDescriptor Type
Field descriptor for the DNS type, written as a number (see DnsType).
Definition: DnsLayer.h:420
static const FieldDescriptor TypeName
Field descriptor for the DNS type name (for example "A", "AAAA" or "CNAME"), written as a string,...
Definition: DnsLayer.h:424
static const FieldDescriptor Class
Field descriptor for the DNS class, written as a number (see DnsClass).
Definition: DnsLayer.h:427
Definition: DnsLayer.h:433
static const FieldDescriptor Name
Field descriptor for the record name, written as a string.
Definition: DnsLayer.h:443
static const FieldDescriptor Ttl
Field descriptor for the TTL, written as a number. For records that don't have a TTL (such as OPT rec...
Definition: DnsLayer.h:458
static const FieldDescriptor Class
Field descriptor for the DNS class, written as a number (see DnsClass). For records that don't have a...
Definition: DnsLayer.h:454
static const FieldDescriptor Data
Field descriptor for the record data, written as a string (see IDnsResourceData::toString())....
Definition: DnsLayer.h:466
static const FieldDescriptor DataLength
Field descriptor for the record data length in bytes, written as a number.
Definition: DnsLayer.h:461
static std::vector< FieldDescriptor > all()
Definition: DnsLayer.h:437
static const FieldDescriptor Type
Field descriptor for the DNS type, written as a number (see DnsType).
Definition: DnsLayer.h:446
static const FieldDescriptor TypeName
Field descriptor for the DNS type name (for example "A", "AAAA" or "CNAME"), written as a string,...
Definition: DnsLayer.h:450
Definition: DnsLayer.h:390
static std::vector< FieldDescriptor > all()
Definition: DnsLayer.h:392
static const FieldDescriptor AdditionalRecords
Field descriptor for the array of additional records; elements described by ResourceObject.
Definition: DnsLayer.h:509
static const FieldDescriptor Opcode
Field descriptor for the operation code, written as a number.
Definition: DnsLayer.h:476
static const FieldDescriptor CheckingDisabled
Field descriptor for the checking disabled flag, written as a boolean.
Definition: DnsLayer.h:494
static constexpr uint16_t MaxID
Maximum field ID used by the layer.
Definition: DnsLayer.h:512
static const FieldDescriptor IsResponse
Field descriptor for the query/response flag, written as a boolean (true for a response).
Definition: DnsLayer.h:473
static const FieldDescriptor RecursionAvailable
Field descriptor for the recursion available flag, written as a boolean.
Definition: DnsLayer.h:488
static const FieldDescriptor Queries
Field descriptor for the array of queries; elements described by QueryObject.
Definition: DnsLayer.h:500
static const FieldDescriptor Answers
Field descriptor for the array of answers; elements described by ResourceObject.
Definition: DnsLayer.h:503
static const FieldDescriptor AuthenticData
Field descriptor for the authenticated data flag, written as a boolean.
Definition: DnsLayer.h:491
static const FieldDescriptor TransactionID
Field descriptor for the transaction ID, written as a hex value.
Definition: DnsLayer.h:470
static const FieldDescriptor AuthoritativeAnswer
Field descriptor for the authoritative answer flag, written as a boolean.
Definition: DnsLayer.h:479
static const FieldDescriptor RecursionDesired
Field descriptor for the recursion desired flag, written as a boolean.
Definition: DnsLayer.h:485
static const FieldDescriptor Truncation
Field descriptor for the truncation flag, written as a boolean.
Definition: DnsLayer.h:482
static const FieldDescriptor ResponseCode
Field descriptor for the response code, written as a number.
Definition: DnsLayer.h:497
static const FieldDescriptor Authorities
Field descriptor for the array of authorities; elements described by ResourceObject.
Definition: DnsLayer.h:506
Definition: DnsLayer.h:598
static std::vector< FieldDescriptor > all()
Definition: DnsLayer.h:601
static const FieldDescriptor TcpMessageLength
Field descriptor for the TCP message length, written as a number.
Definition: DnsLayer.h:609
Definition: Serializers.h:18
static std::vector< FieldDescriptor > all()
Definition: Layer.h:214
static constexpr uint16_t MaxID
Maximum field ID used by the layer.
Definition: Layer.h:229
Definition: Serializers.h:49
ObjectFieldDescriptor(uint16_t fieldId, std::string fieldName)
Definition: Serializers.h:53
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