PcapPlusPlus  19.12
DnsResource.h
Go to the documentation of this file.
1 #ifndef PACKETPP_DNS_RESOURCE
2 #define PACKETPP_DNS_RESOURCE
3 
4 #include "DnsLayer.h"
5 #include "DnsLayerEnums.h"
6 #include "DnsResourceData.h"
7 #include <stdio.h>
8 #include <string>
9 #include <stdint.h>
10 
12 
17 namespace pcpp
18 {
19  // forward declarations
20  class DnsLayer;
21  class IDnsResourceData;
22  class DnsResourceDataPtr;
23 
24 
31  {
32  protected:
33  friend class DnsLayer;
34  friend class IDnsResourceData;
35 
36  protected:
37  DnsLayer* m_DnsLayer;
38  size_t m_OffsetInLayer;
39  IDnsResource* m_NextResource;
40  std::string m_DecodedName;
41  size_t m_NameLength;
42  uint8_t* m_ExternalRawData;
43 
44  IDnsResource(DnsLayer* dnsLayer, size_t offsetInLayer);
45 
46  IDnsResource(uint8_t* emptyRawData);
47 
48  size_t decodeName(const char* encodedName, char* result, int iteration = 1);
49  void encodeName(const std::string& decodedName, char* result, size_t& resultLen);
50 
51  IDnsResource* getNextResource() const { return m_NextResource; }
52  void setNexResource(IDnsResource* next) { m_NextResource = next; }
53 
54  uint8_t* getRawData() const;
55 
56  void setDnsLayer(DnsLayer* dnsLayer, size_t offsetInLayer);
57 
58  public:
59 
60  virtual ~IDnsResource() {}
61 
65  DnsType getDnsType() const;
66 
71  void setDnsType(DnsType newType);
72 
76  DnsClass getDnsClass() const;
77 
82  void setDnsClass(DnsClass newClass);
83 
87  std::string getName() const { return m_DecodedName; }
88 
92  size_t getNameOffset() const { return m_OffsetInLayer; }
93 
107  bool setName(const std::string& newName);
108 
109 
110  // abstract methods
111 
115  virtual size_t getSize() const = 0;
116 
120  virtual DnsResourceType getType() const = 0;
121  };
122 
123 
128  class DnsQuery : public IDnsResource
129  {
130  friend class DnsLayer;
131 
132  private:
133  DnsQuery(DnsLayer* dnsLayer, size_t offsetInLayer) : IDnsResource(dnsLayer, offsetInLayer) {}
134 
135  DnsQuery(uint8_t* emptyRawData) : IDnsResource(emptyRawData) {}
136 
137  public:
138  virtual ~DnsQuery() {}
139 
140  // implementation of abstract methods
141  virtual size_t getSize() const { return m_NameLength + 2*sizeof(uint16_t); }
142  virtual DnsResourceType getType() const { return DnsQueryType; }
143  };
144 
145 
150  class DnsResource : public IDnsResource
151  {
152  friend class DnsLayer;
153 
154  private:
155  DnsResourceType m_ResourceType;
156 
157  DnsResource(DnsLayer* dnsLayer, size_t offsetInLayer, DnsResourceType resourceType) : IDnsResource(dnsLayer, offsetInLayer) { m_ResourceType = resourceType; }
158 
159  DnsResource(uint8_t* emptyRawData, DnsResourceType resType) : IDnsResource(emptyRawData), m_ResourceType(resType) {}
160 
161  public:
162  virtual ~DnsResource() {}
163 
167  uint32_t getTTL() const;
168 
173  void setTTL(uint32_t newTTL);
174 
178  size_t getDataLength() const;
179 
191  DnsResourceDataPtr getData() const;
192 
196  size_t getDataOffset() const;
197 
213  bool setData(IDnsResourceData* data);
214 
220  uint16_t getCustomDnsClass() const;
221 
227  void setCustomDnsClass(uint16_t customValue);
228 
229  // implementation of abstract methods
230  virtual size_t getSize() const { return m_NameLength + 3*sizeof(uint16_t) + sizeof(uint32_t) + getDataLength(); }
231  virtual DnsResourceType getType() const { return m_ResourceType; }
232 
233  };
234 
235 }
236 
237 #endif // PACKETPP_DNS_RESOURCE
pcpp::IDnsResource::getType
virtual DnsResourceType getType() const =0
pcpp::IDnsResource::setName
bool setName(const std::string &newName)
DnsLayerEnums.h
pcpp::DnsClass
DnsClass
Definition: DnsLayerEnums.h:127
pcpp::DnsQuery::getType
virtual DnsResourceType getType() const
Definition: DnsResource.h:142
pcpp::IDnsResourceData
Definition: DnsResourceData.h:39
pcpp::IDnsResource::getDnsType
DnsType getDnsType() const
pcpp::DnsResource::getData
DnsResourceDataPtr getData() const
pcpp::DnsResource::getSize
virtual size_t getSize() const
Definition: DnsResource.h:230
pcpp::IDnsResource::setDnsType
void setDnsType(DnsType newType)
pcpp::IDnsResource::getDnsClass
DnsClass getDnsClass() const
pcpp::DnsResource::setData
bool setData(IDnsResourceData *data)
pcpp::IDnsResource
Definition: DnsResource.h:30
DnsResourceData.h
pcpp::DnsResource::getType
virtual DnsResourceType getType() const
Definition: DnsResource.h:231
pcpp::DnsQuery::getSize
virtual size_t getSize() const
Definition: DnsResource.h:141
pcpp::IDnsResource::setDnsClass
void setDnsClass(DnsClass newClass)
pcpp::DnsResource::setCustomDnsClass
void setCustomDnsClass(uint16_t customValue)
pcpp::DnsResource::getDataLength
size_t getDataLength() const
pcpp::DnsType
DnsType
Definition: DnsLayerEnums.h:15
pcpp::IDnsResource::getNameOffset
size_t getNameOffset() const
Definition: DnsResource.h:92
pcpp::DnsResource::getTTL
uint32_t getTTL() const
pcpp::DnsResource::getCustomDnsClass
uint16_t getCustomDnsClass() const
pcpp::IDnsResource::getName
std::string getName() const
Definition: DnsResource.h:87
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::DnsResource::getDataOffset
size_t getDataOffset() const
pcpp::DnsResourceType
DnsResourceType
Definition: DnsLayerEnums.h:145
pcpp::DnsQueryType
Definition: DnsLayerEnums.h:148
pcpp::DnsResource::setTTL
void setTTL(uint32_t newTTL)
pcpp::DnsQuery
Definition: DnsResource.h:128
pcpp::IDnsResource::getSize
virtual size_t getSize() const =0
pcpp::DnsResource
Definition: DnsResource.h:150
pcpp::DnsResourceDataPtr
Definition: DnsResourceData.h:93
pcpp::DnsLayer
Definition: DnsLayer.h:99
DnsLayer.h