PcapPlusPlus  23.09
DhcpV6Layer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_DHCPV6_LAYER
2 #define PACKETPP_DHCPV6_LAYER
3 
4 #include "Layer.h"
5 #include "TLVData.h"
6 
8 
13 namespace pcpp
14 {
19  {
48  };
49 
59  {
188  };
189 
195  class DhcpV6Option : public TLVRecord<uint16_t, uint16_t>
196  {
197  public:
202  explicit DhcpV6Option(uint8_t* optionRawData) : TLVRecord(optionRawData) { }
203 
207  virtual ~DhcpV6Option() { }
208 
212  DhcpV6OptionType getType() const;
213 
217  std::string getValueAsHexString() const;
218 
219  // implement abstract methods
220 
221  size_t getTotalSize() const;
222  size_t getDataSize() const;
223  };
224 
231  {
232  public:
239  DhcpV6OptionBuilder(DhcpV6OptionType optionType, const std::string& optionValueAsHexStream) :
240  TLVRecordBuilder(static_cast<uint16_t>(optionType), optionValueAsHexStream, true) { }
241 
249  DhcpV6OptionBuilder(DhcpV6OptionType optionType, const uint8_t* optionValue, uint8_t optionValueLen) :
250  TLVRecordBuilder(static_cast<uint16_t>(optionType), optionValue, optionValueLen) {}
251 
256  DhcpV6Option build() const;
257  };
258 
264  {
266  uint8_t messageType;
268  uint8_t transactionId1;
270  uint8_t transactionId2;
272  uint8_t transactionId3;
273  };
274 
279  class DhcpV6Layer : public Layer
280  {
281  public:
282 
290  DhcpV6Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
291 
297  DhcpV6Layer(DhcpV6MessageType messageType, uint32_t transactionId);
298 
302  DhcpV6MessageType getMessageType() const;
303 
307  std::string getMessageTypeAsString() const;
308 
313  void setMessageType(DhcpV6MessageType messageType);
314 
318  uint32_t getTransactionID() const;
319 
324  void setTransactionID(uint32_t transactionId) const;
325 
330  DhcpV6Option getFirstOptionData() const;
331 
339  DhcpV6Option getNextOptionData(DhcpV6Option dhcpv6Option) const;
340 
347  DhcpV6Option getOptionData(DhcpV6OptionType option) const;
348 
352  size_t getOptionCount() const;
353 
360  DhcpV6Option addOption(const DhcpV6OptionBuilder& optionBuilder);
361 
369  DhcpV6Option addOptionAfter(const DhcpV6OptionBuilder& optionBuilder, DhcpV6OptionType optionType);
370 
378  DhcpV6Option addOptionBefore(const DhcpV6OptionBuilder& optionBuilder, DhcpV6OptionType optionType);
379 
385  bool removeOption(DhcpV6OptionType optionType);
386 
391  bool removeAllOptions();
392 
398  static inline bool isDhcpV6Port(uint16_t port);
399 
406  static inline bool isDataValid(const uint8_t* data, size_t dataLen);
407 
408  // implement abstract methods
409 
413  void parseNextLayer() {}
414 
418  size_t getHeaderLen() const { return m_DataLen; }
419 
424 
425  std::string toString() const;
426 
428 
429  private:
430  uint8_t* getOptionsBasePtr() const { return m_Data + sizeof(dhcpv6_header); }
431  dhcpv6_header* getDhcpHeader() const { return (dhcpv6_header*)m_Data; }
432  DhcpV6Option addOptionAt(const DhcpV6OptionBuilder& optionBuilder, int offset);
433 
434  TLVRecordReader<DhcpV6Option> m_OptionReader;
435  };
436 
437 
438  // implementation of inline methods
439 
440  bool DhcpV6Layer::isDhcpV6Port(uint16_t port)
441  {
442  return (port == 546) || (port == 547);
443 
444  }
445 
446  bool DhcpV6Layer::isDataValid(const uint8_t* data, size_t dataLen)
447  {
448  return data && dataLen >= sizeof(dhcpv6_header);
449  }
450 
451 }
452 # endif // PACKETPP_DHCPV6_LAYER
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:333
DhcpV6OptionType
Definition: DhcpV6Layer.h:58
Definition: DhcpV6Layer.h:133
Definition: DhcpV6Layer.h:123
Definition: DhcpV6Layer.h:145
Definition: DhcpV6Layer.h:115
Definition: DhcpV6Layer.h:101
Definition: DhcpV6Layer.h:85
Definition: DhcpV6Layer.h:171
Definition: DhcpV6Layer.h:113
Definition: DhcpV6Layer.h:179
Definition: DhcpV6Layer.h:91
void parseNextLayer()
Definition: DhcpV6Layer.h:413
Definition: DhcpV6Layer.h:230
Definition: ProtocolType.h:348
static bool isDhcpV6Port(uint16_t port)
Definition: DhcpV6Layer.h:440
Definition: DhcpV6Layer.h:61
Definition: DhcpV6Layer.h:117
Definition: TLVData.h:376
Definition: Layer.h:70
DhcpV6Option(uint8_t *optionRawData)
Definition: DhcpV6Layer.h:202
uint8_t transactionId3
Definition: DhcpV6Layer.h:272
Definition: DhcpV6Layer.h:37
Definition: DhcpV6Layer.h:95
Definition: TLVData.h:24
Definition: DhcpV6Layer.h:63
Definition: Packet.h:26
Definition: DhcpV6Layer.h:183
Definition: DhcpV6Layer.h:25
Definition: DhcpV6Layer.h:129
Definition: DhcpV6Layer.h:35
Definition: DhcpV6Layer.h:187
Definition: DhcpV6Layer.h:109
Definition: DhcpV6Layer.h:107
Definition: DhcpV6Layer.h:75
uint8_t transactionId1
Definition: DhcpV6Layer.h:268
Definition: DhcpV6Layer.h:135
Definition: DhcpV6Layer.h:137
size_t getTotalSize() const
Definition: DhcpV6Layer.h:119
Definition: TLVData.h:217
Definition: DhcpV6Layer.h:65
DhcpV6OptionType getType() const
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: DhcpV6Layer.h:446
Definition: DhcpV6Layer.h:153
Definition: DhcpV6Layer.h:39
Definition: DhcpV6Layer.h:151
Definition: DhcpV6Layer.h:143
Definition: DhcpV6Layer.h:169
Definition: DhcpV6Layer.h:47
Definition: DhcpV6Layer.h:23
Definition: DhcpV6Layer.h:73
Definition: DhcpV6Layer.h:149
uint8_t transactionId2
Definition: DhcpV6Layer.h:270
Definition: DhcpV6Layer.h:79
Definition: DhcpV6Layer.h:83
Definition: DhcpV6Layer.h:121
Definition: DhcpV6Layer.h:97
Definition: DhcpV6Layer.h:147
size_t getHeaderLen() const
Definition: DhcpV6Layer.h:418
Definition: DhcpV6Layer.h:81
Definition: DhcpV6Layer.h:181
Definition: DhcpV6Layer.h:279
Definition: DhcpV6Layer.h:125
DhcpV6OptionBuilder(DhcpV6OptionType optionType, const std::string &optionValueAsHexStream)
Definition: DhcpV6Layer.h:239
Definition: DhcpV6Layer.h:93
Definition: DhcpV6Layer.h:161
virtual ~DhcpV6Option()
Definition: DhcpV6Layer.h:207
Definition: DhcpV6Layer.h:87
Definition: DhcpV6Layer.h:43
Definition: DhcpV6Layer.h:127
uint8_t messageType
Definition: DhcpV6Layer.h:266
Definition: DhcpV6Layer.h:105
Definition: DhcpV6Layer.h:131
Definition: DhcpV6Layer.h:31
DhcpV6OptionBuilder(DhcpV6OptionType optionType, const uint8_t *optionValue, uint8_t optionValueLen)
Definition: DhcpV6Layer.h:249
Definition: DhcpV6Layer.h:165
Definition: DhcpV6Layer.h:139
Definition: DhcpV6Layer.h:71
void computeCalculateFields()
Definition: DhcpV6Layer.h:423
Definition: DhcpV6Layer.h:33
Definition: DhcpV6Layer.h:89
Definition: DhcpV6Layer.h:45
Definition: DhcpV6Layer.h:167
Definition: DhcpV6Layer.h:163
Definition: DhcpV6Layer.h:21
size_t getDataSize() const
DhcpV6MessageType
Definition: DhcpV6Layer.h:18
Definition: DhcpV6Layer.h:173
Definition: DhcpV6Layer.h:141
Definition: DhcpV6Layer.h:263
Definition: DhcpV6Layer.h:111
Definition: DhcpV6Layer.h:195
Definition: DhcpV6Layer.h:103
Definition: DhcpV6Layer.h:157
Definition: DhcpV6Layer.h:159
Definition: DhcpV6Layer.h:77
std::string getValueAsHexString() const
OsiModelLayer getOsiModelLayer() const
Definition: DhcpV6Layer.h:427
Definition: DhcpV6Layer.h:99
Definition: DhcpV6Layer.h:185
Definition: DhcpV6Layer.h:67
Definition: DhcpV6Layer.h:29
Definition: DhcpV6Layer.h:41
Definition: DhcpV6Layer.h:175
Definition: DhcpV6Layer.h:69
Definition: DhcpV6Layer.h:155
Definition: DhcpV6Layer.h:177
Definition: DhcpV6Layer.h:27