PcapPlusPlus  22.05
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  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 
314  void setMessageType(DhcpV6MessageType messageType);
315 
319  uint32_t getTransactionID() const;
320 
326  void setTransactionID(uint32_t transactionId) const;
327 
332  DhcpV6Option getFirstOptionData() const;
333 
341  DhcpV6Option getNextOptionData(DhcpV6Option dhcpv6Option) const;
342 
349  DhcpV6Option getOptionData(DhcpV6OptionType option) const;
350 
354  size_t getOptionCount() const;
355 
362  DhcpV6Option addOption(const DhcpV6OptionBuilder& optionBuilder);
363 
371  DhcpV6Option addOptionAfter(const DhcpV6OptionBuilder& optionBuilder, DhcpV6OptionType optionType);
372 
380  DhcpV6Option addOptionBefore(const DhcpV6OptionBuilder& optionBuilder, DhcpV6OptionType optionType);
381 
387  bool removeOption(DhcpV6OptionType optionType);
388 
393  bool removeAllOptions();
394 
400  static inline bool isDhcpV6Port(uint16_t port);
401 
408  static inline bool isDataValid(const uint8_t* data, size_t dataLen);
409 
410  // implement abstract methods
411 
415  void parseNextLayer() {}
416 
420  size_t getHeaderLen() const { return m_DataLen; }
421 
426 
427  std::string toString() const;
428 
430 
431  private:
432  uint8_t* getOptionsBasePtr() const { return m_Data + sizeof(dhcpv6_header); }
433  dhcpv6_header* getDhcpHeader() const { return (dhcpv6_header*)m_Data; }
434  DhcpV6Option addOptionAt(const DhcpV6OptionBuilder& optionBuilder, int offset);
435 
436  TLVRecordReader<DhcpV6Option> m_OptionReader;
437  };
438 
439 
440  // implementation of inline methods
441 
442  bool DhcpV6Layer::isDhcpV6Port(uint16_t port)
443  {
444  return (port == 546) || (port == 547);
445 
446  }
447 
448  bool DhcpV6Layer::isDataValid(const uint8_t* data, size_t dataLen)
449  {
450  return dataLen >= sizeof(dhcpv6_header);
451  }
452 
453 }
454 # endif // PACKETPP_DHCPV6_LAYER
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:263
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:415
Definition: DhcpV6Layer.h:230
Definition: ProtocolType.h:278
static bool isDhcpV6Port(uint16_t port)
Definition: DhcpV6Layer.h:442
Definition: DhcpV6Layer.h:61
Definition: DhcpV6Layer.h:117
Definition: TLVData.h:363
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:207
Definition: DhcpV6Layer.h:65
DhcpV6OptionType getType() const
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: DhcpV6Layer.h:448
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:420
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:425
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:429
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