PcapPlusPlus
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  inline IDnsResource* getNextResource() { return m_NextResource; }
52  inline void setNexResource(IDnsResource* next) { m_NextResource = next; }
53 
54  uint8_t* getRawData();
55 
56  void setDnsLayer(DnsLayer* dnsLayer, size_t offsetInLayer);
57 
58  public:
59 
60  virtual ~IDnsResource() {}
61 
66 
71  void setDnsType(DnsType newType);
72 
77 
82  void setDnsClass(DnsClass newClass);
83 
87  std::string getName() { return m_DecodedName; }
88 
92  size_t getNameOffset() { return m_OffsetInLayer; }
93 
107  bool setName(const std::string& newName);
108 
109 
110  // abstract methods
111 
115  virtual size_t getSize() = 0;
116 
120  virtual DnsResourceType getType() = 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  // abstract methods
141  virtual size_t getSize() { return m_NameLength + 2*sizeof(uint16_t); }
142  virtual DnsResourceType getType() { 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();
168 
173  void setTTL(uint32_t newTTL);
174 
178  size_t getDataLength();
179 
192 
196  size_t getDataOffset();
197 
213  bool setData(IDnsResourceData* data);
214 
220  uint16_t getCustomDnsClass();
221 
227  void setCustomDnsClass(uint16_t customValue);
228 
229  // abstract methods
230  virtual size_t getSize() { return m_NameLength + 3*sizeof(uint16_t) + sizeof(uint32_t) + getDataLength(); }
231  virtual DnsResourceType getType() { return m_ResourceType; }
232 
233  };
234 
235 }
236 
237 #endif // PACKETPP_DNS_RESOURCE
Definition: DnsLayerEnums.h:148
DnsClass
Definition: DnsLayerEnums.h:127
size_t getDataLength()
Definition: DnsResourceData.h:88
void setCustomDnsClass(uint16_t customValue)
uint16_t getCustomDnsClass()
Definition: DnsResource.h:30
bool setData(IDnsResourceData *data)
virtual size_t getSize()
Definition: DnsResource.h:141
void setDnsType(DnsType newType)
uint32_t getTTL()
DnsResourceType
Definition: DnsLayerEnums.h:145
size_t getNameOffset()
Definition: DnsResource.h:92
virtual DnsResourceType getType()=0
DnsClass getDnsClass()
virtual DnsResourceType getType()
Definition: DnsResource.h:231
virtual DnsResourceType getType()
Definition: DnsResource.h:142
void setTTL(uint32_t newTTL)
DnsType getDnsType()
DnsResourceDataPtr getData()
bool setName(const std::string &newName)
Definition: DnsResource.h:150
Definition: DnsLayer.h:104
DnsType
Definition: DnsLayerEnums.h:15
size_t getDataOffset()
std::string getName()
Definition: DnsResource.h:87
Definition: DnsResource.h:128
virtual size_t getSize()
Definition: DnsResource.h:230
The main namespace for the PcapPlusPlus lib.
Definition: DnsResourceData.h:34
void setDnsClass(DnsClass newClass)
virtual size_t getSize()=0