PcapPlusPlus  20.08+
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  const 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
const std::string & getName() const
Definition: DnsResource.h:87
The main namespace for the PcapPlusPlus lib.
void setDnsType(DnsType newType)
bool setName(const std::string &newName)
virtual size_t getSize() const
Definition: DnsResource.h:230
DnsType getDnsType() const
void setDnsClass(DnsClass newClass)
DnsClass
Definition: DnsLayerEnums.h:127
Definition: DnsResourceData.h:40
DnsType
Definition: DnsLayerEnums.h:15
Definition: DnsLayer.h:97
DnsClass getDnsClass() const
virtual size_t getSize() const
Definition: DnsResource.h:141
size_t getNameOffset() const
Definition: DnsResource.h:92
virtual DnsResourceType getType() const
Definition: DnsResource.h:231
virtual size_t getSize() const =0
DnsResourceType
Definition: DnsLayerEnums.h:145
virtual DnsResourceType getType() const =0
Definition: DnsLayerEnums.h:148
Definition: DnsResource.h:150
Definition: DnsResource.h:30
Definition: DnsResource.h:128
Definition: DnsResourceData.h:94
virtual DnsResourceType getType() const
Definition: DnsResource.h:142