PcapPlusPlus  Next
DhcpV6Layer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 #include "TLVData.h"
5 
7 
12 namespace pcpp
13 {
18  {
47  };
48 
58  {
187  DHCPV6_OPT_MUD_URL = 112
188  };
189 
195  class DhcpV6Option : public TLVRecord<uint16_t, uint16_t>
196  {
197  public:
202  explicit DhcpV6Option(uint8_t* optionRawData) : TLVRecord(optionRawData)
203  {}
204 
208  ~DhcpV6Option() override = default;
209 
214 
218  std::string getValueAsHexString() const;
219 
220  // implement abstract methods
221 
222  size_t getTotalSize() const override;
223  size_t getDataSize() const override;
224  };
225 
232  {
233  public:
240  DhcpV6OptionBuilder(DhcpV6OptionType optionType, const std::string& optionValueAsHexStream)
241  : TLVRecordBuilder(static_cast<uint16_t>(optionType), optionValueAsHexStream, true)
242  {}
243 
252  DhcpV6OptionBuilder(DhcpV6OptionType optionType, const uint8_t* optionValue, uint8_t optionValueLen)
253  : TLVRecordBuilder(static_cast<uint16_t>(optionType), optionValue, optionValueLen)
254  {}
255 
261  };
262 
268  {
270  uint8_t messageType;
272  uint8_t transactionId1;
274  uint8_t transactionId2;
276  uint8_t transactionId3;
277  };
278 
283  class DhcpV6Layer : public Layer
284  {
285  public:
293  DhcpV6Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
294 
301  DhcpV6Layer(DhcpV6MessageType messageType, uint32_t transactionId);
302 
307 
311  std::string getMessageTypeAsString() const;
312 
318 
322  uint32_t getTransactionID() const;
323 
328  void setTransactionID(uint32_t transactionId) const;
329 
335 
344 
352 
356  size_t getOptionCount() const;
357 
365 
374 
383 
389  bool removeOption(DhcpV6OptionType optionType);
390 
396 
402  static inline bool isDhcpV6Port(uint16_t port);
403 
410  static inline bool isDataValid(const uint8_t* data, size_t dataLen);
411 
412  // implement abstract methods
413 
417  void parseNextLayer() override
418  {}
419 
423  size_t getHeaderLen() const override
424  {
425  return m_DataLen;
426  }
427 
431  void computeCalculateFields() override
432  {}
433 
434  std::string toString() const override;
435 
437  {
439  }
440 
441  private:
442  uint8_t* getOptionsBasePtr() const
443  {
444  return m_Data + sizeof(dhcpv6_header);
445  }
446  dhcpv6_header* getDhcpHeader() const
447  {
448  return reinterpret_cast<dhcpv6_header*>(m_Data);
449  }
450  DhcpV6Option addOptionAt(const DhcpV6OptionBuilder& optionBuilder, int offset);
451 
452  TLVRecordReader<DhcpV6Option> m_OptionReader;
453  };
454 
455  // implementation of inline methods
456 
457  bool DhcpV6Layer::isDhcpV6Port(uint16_t port)
458  {
459  return (port == 546) || (port == 547);
460  }
461 
462  bool DhcpV6Layer::isDataValid(const uint8_t* data, size_t dataLen)
463  {
464  return data && dataLen >= sizeof(dhcpv6_header);
465  }
466 
467 } // namespace pcpp
Definition: DhcpV6Layer.h:284
std::string getMessageTypeAsString() const
DhcpV6Option getNextOptionData(DhcpV6Option dhcpv6Option) const
std::string toString() const override
DhcpV6Option addOptionAfter(const DhcpV6OptionBuilder &optionBuilder, DhcpV6OptionType optionType)
bool removeOption(DhcpV6OptionType optionType)
void setMessageType(DhcpV6MessageType messageType)
DhcpV6Option addOptionBefore(const DhcpV6OptionBuilder &optionBuilder, DhcpV6OptionType optionType)
size_t getHeaderLen() const override
Definition: DhcpV6Layer.h:423
DhcpV6Layer(DhcpV6MessageType messageType, uint32_t transactionId)
void setTransactionID(uint32_t transactionId) const
void parseNextLayer() override
Definition: DhcpV6Layer.h:417
DhcpV6Option getOptionData(DhcpV6OptionType option) const
uint32_t getTransactionID() const
size_t getOptionCount() const
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: DhcpV6Layer.h:462
OsiModelLayer getOsiModelLayer() const override
Definition: DhcpV6Layer.h:436
DhcpV6Option getFirstOptionData() const
void computeCalculateFields() override
Definition: DhcpV6Layer.h:431
DhcpV6Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
DhcpV6MessageType getMessageType() const
DhcpV6Option addOption(const DhcpV6OptionBuilder &optionBuilder)
static bool isDhcpV6Port(uint16_t port)
Definition: DhcpV6Layer.h:457
Definition: DhcpV6Layer.h:232
DhcpV6Option build() const
DhcpV6OptionBuilder(DhcpV6OptionType optionType, const std::string &optionValueAsHexStream)
Definition: DhcpV6Layer.h:240
DhcpV6OptionBuilder(DhcpV6OptionType optionType, const uint8_t *optionValue, uint8_t optionValueLen)
Definition: DhcpV6Layer.h:252
Definition: DhcpV6Layer.h:196
size_t getDataSize() const override
~DhcpV6Option() override=default
size_t getTotalSize() const override
std::string getValueAsHexString() const
DhcpV6Option(uint8_t *optionRawData)
Definition: DhcpV6Layer.h:202
DhcpV6OptionType getType() const
Definition: Layer.h:69
Definition: Packet.h:27
Definition: TLVData.h:419
Definition: TLVData.h:23
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:364
@ OsiModelApplicationLayer
Definition: ProtocolType.h:378
DhcpV6MessageType
Definition: DhcpV6Layer.h:18
@ DHCPV6_REQUEST
Definition: DhcpV6Layer.h:26
@ DHCPV6_SOLICIT
Definition: DhcpV6Layer.h:22
@ DHCPV6_RELAY_REPLY
Definition: DhcpV6Layer.h:46
@ DHCPV6_INFORMATION_REQUEST
Definition: DhcpV6Layer.h:42
@ DHCPV6_ADVERTISE
Definition: DhcpV6Layer.h:24
@ DHCPV6_REBIND
Definition: DhcpV6Layer.h:32
@ DHCPV6_UNKNOWN_MSG_TYPE
Definition: DhcpV6Layer.h:20
@ DHCPV6_CONFIRM
Definition: DhcpV6Layer.h:28
@ DHCPV6_RENEW
Definition: DhcpV6Layer.h:30
@ DHCPV6_REPLY
Definition: DhcpV6Layer.h:34
@ DHCPV6_RECONFIGURE
Definition: DhcpV6Layer.h:40
@ DHCPV6_DECLINE
Definition: DhcpV6Layer.h:38
@ DHCPV6_RELEASE
Definition: DhcpV6Layer.h:36
@ DHCPV6_RELAY_FORWARD
Definition: DhcpV6Layer.h:44
DhcpV6OptionType
Definition: DhcpV6Layer.h:58
@ DHCPV6_OPT_ERP_LOCAL_DOMAIN_NAME
Definition: DhcpV6Layer.h:179
@ DHCPV6_OPT_NISP_DOMAIN_NAME
Definition: DhcpV6Layer.h:118
@ DHCPV6_OPT_CLT_TIME
Definition: DhcpV6Layer.h:149
@ DHCPV6_OPT_CLIENT_DATA
Definition: DhcpV6Layer.h:147
@ DHCPV6_OPT_MUD_URL
Definition: DhcpV6Layer.h:187
@ DHCPV6_OPT_DOMAIN_LIST
Definition: DhcpV6Layer.h:106
@ DHCPV6_OPT_SIP_SERVERS_A
Definition: DhcpV6Layer.h:102
@ DHCPV6_OPT_PANA_AGENT
Definition: DhcpV6Layer.h:137
@ DHCPV6_OPT_MIP6_HNINF
Definition: DhcpV6Layer.h:155
@ DHCPV6_OPT_MIP6_RELAY
Definition: DhcpV6Layer.h:157
@ DHCPV6_OPT_IPV6_FQDN_MOS
Definition: DhcpV6Layer.h:167
@ DHCPV6_OPT_IA_NA
Definition: DhcpV6Layer.h:66
@ DHCPV6_OPT_USER_CLASS
Definition: DhcpV6Layer.h:88
@ DHCPV6_OPT_NIS_SERVERS
Definition: DhcpV6Layer.h:112
@ DHCPV6_OPT_LQ_QUERY
Definition: DhcpV6Layer.h:145
@ DHCPV6_OPT_RELAY_MSG
Definition: DhcpV6Layer.h:78
@ DHCPV6_OPT_SUBSCRIBER_ID
Definition: DhcpV6Layer.h:132
@ DHCPV6_OPT_IA_TA
Definition: DhcpV6Layer.h:68
@ DHCPV6_OPT_LQ_RELAY_DATA
Definition: DhcpV6Layer.h:151
@ DHCPV6_OPT_NTP_SERVER
Definition: DhcpV6Layer.h:169
@ DHCPV6_OPT_NEW_POSIX_TIMEZONE
Definition: DhcpV6Layer.h:139
@ DHCPV6_OPT_IPH6_ADDRESS_MOS
Definition: DhcpV6Layer.h:165
@ DHCPV6_OPT_CLIENT_FQDN
Definition: DhcpV6Layer.h:134
@ DHCPV6_OPT_INTERFACE_ID
Definition: DhcpV6Layer.h:94
@ DHCPV6_OPT_BOOTFILE_URL
Definition: DhcpV6Layer.h:171
@ DHCPV6_OPT_NEW_TZDB_TIMEZONE
Definition: DhcpV6Layer.h:141
@ DHCPV6_OPT_BOOTFILE_PARAM
Definition: DhcpV6Layer.h:173
@ DHCPV6_OPT_DNS_SERVERS
Definition: DhcpV6Layer.h:104
@ DHCPV6_OPT_CLIENT_ARCH_TYPE
Definition: DhcpV6Layer.h:175
@ DHCPV6_OPT_AUTH
Definition: DhcpV6Layer.h:80
@ DHCPV6_OPT_STATUS_CODE
Definition: DhcpV6Layer.h:84
@ DHCPV6_OPT_SIP_SERVERS_D
Definition: DhcpV6Layer.h:100
@ DHCPV6_OPT_UNKNOWN
Definition: DhcpV6Layer.h:60
@ DHCPV6_OPT_IAADDR
Definition: DhcpV6Layer.h:70
@ DHCPV6_OPT_NIS_DOMAIN_NAME
Definition: DhcpV6Layer.h:116
@ DHCPV6_OPT_REMOTE_ID
Definition: DhcpV6Layer.h:130
@ DHCPV6_OPT_RECONF_ACCEPT
Definition: DhcpV6Layer.h:98
@ DHCPV6_OPT_RAPID_COMMIT
Definition: DhcpV6Layer.h:86
@ DHCPV6_OPT_V6_LOST
Definition: DhcpV6Layer.h:159
@ DHCPV6_OPT_CAPWAP_AC_V6
Definition: DhcpV6Layer.h:161
@ DHCPV6_OPT_VENDOR_CLASS
Definition: DhcpV6Layer.h:90
@ DHCPV6_OPT_LQ_CLIENT_LINK
Definition: DhcpV6Layer.h:153
@ DHCPV6_OPT_BCMCS_SERVER_A
Definition: DhcpV6Layer.h:126
@ DHCPV6_OPT_NII
Definition: DhcpV6Layer.h:177
@ DHCPV6_OPT_INFORMATION_REFRESH_TIME
Definition: DhcpV6Layer.h:122
@ DHCPV6_OPT_IA_PD
Definition: DhcpV6Layer.h:108
@ DHCPV6_OPT_ELAPSED_TIME
Definition: DhcpV6Layer.h:76
@ DHCPV6_OPT_RECONF_MSG
Definition: DhcpV6Layer.h:96
@ DHCPV6_OPT_BCMCS_SERVER_D
Definition: DhcpV6Layer.h:124
@ DHCPV6_OPT_UNICAST
Definition: DhcpV6Layer.h:82
@ DHCPV6_OPT_ORO
Definition: DhcpV6Layer.h:72
@ DHCPV6_OPT_VENDOR_OPTS
Definition: DhcpV6Layer.h:92
@ DHCPV6_OPT_VSS
Definition: DhcpV6Layer.h:183
@ DHCPV6_OPT_RELAY_SUPPLIED_OPTIONS
Definition: DhcpV6Layer.h:181
@ DHCPV6_OPT_IAPREFIX
Definition: DhcpV6Layer.h:110
@ DHCPV6_OPT_SERVERID
Definition: DhcpV6Layer.h:64
@ DHCPV6_OPT_CLIENTID
Definition: DhcpV6Layer.h:62
@ DHCPV6_OPT_ERO
Definition: DhcpV6Layer.h:143
@ DHCPV6_OPT_CLIENT_LINKLAYER_ADDR
Definition: DhcpV6Layer.h:185
@ DHCPV6_OPT_GEOCONF_CIVIC
Definition: DhcpV6Layer.h:128
@ DHCPV6_OPT_PREFERENCE
Definition: DhcpV6Layer.h:74
@ DHCPV6_OPT_SNTP_SERVERS
Definition: DhcpV6Layer.h:120
@ DHCPV6_OPT_RELAY_ID
Definition: DhcpV6Layer.h:163
@ DHCPV6_OPT_NISP_SERVERS
Definition: DhcpV6Layer.h:114
Definition: DhcpV6Layer.h:268
uint8_t messageType
Definition: DhcpV6Layer.h:270
uint8_t transactionId3
Definition: DhcpV6Layer.h:276
uint8_t transactionId2
Definition: DhcpV6Layer.h:274
uint8_t transactionId1
Definition: DhcpV6Layer.h:272