PcapPlusPlus  24.09
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  virtual ~DhcpV6Option()
209  {}
210 
215 
219  std::string getValueAsHexString() const;
220 
221  // implement abstract methods
222 
223  size_t getTotalSize() const;
224  size_t getDataSize() const;
225  };
226 
233  {
234  public:
241  DhcpV6OptionBuilder(DhcpV6OptionType optionType, const std::string& optionValueAsHexStream)
242  : TLVRecordBuilder(static_cast<uint16_t>(optionType), optionValueAsHexStream, true)
243  {}
244 
253  DhcpV6OptionBuilder(DhcpV6OptionType optionType, const uint8_t* optionValue, uint8_t optionValueLen)
254  : TLVRecordBuilder(static_cast<uint16_t>(optionType), optionValue, optionValueLen)
255  {}
256 
262  };
263 
269  {
271  uint8_t messageType;
273  uint8_t transactionId1;
275  uint8_t transactionId2;
277  uint8_t transactionId3;
278  };
279 
284  class DhcpV6Layer : public Layer
285  {
286  public:
294  DhcpV6Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
295 
302  DhcpV6Layer(DhcpV6MessageType messageType, uint32_t transactionId);
303 
308 
312  std::string getMessageTypeAsString() const;
313 
319 
323  uint32_t getTransactionID() const;
324 
329  void setTransactionID(uint32_t transactionId) const;
330 
336 
345 
353 
357  size_t getOptionCount() const;
358 
366 
375 
384 
390  bool removeOption(DhcpV6OptionType optionType);
391 
397 
403  static inline bool isDhcpV6Port(uint16_t port);
404 
411  static inline bool isDataValid(const uint8_t* data, size_t dataLen);
412 
413  // implement abstract methods
414 
419  {}
420 
424  size_t getHeaderLen() const
425  {
426  return m_DataLen;
427  }
428 
433  {}
434 
435  std::string toString() const;
436 
438  {
440  }
441 
442  private:
443  uint8_t* getOptionsBasePtr() const
444  {
445  return m_Data + sizeof(dhcpv6_header);
446  }
447  dhcpv6_header* getDhcpHeader() const
448  {
449  return (dhcpv6_header*)m_Data;
450  }
451  DhcpV6Option addOptionAt(const DhcpV6OptionBuilder& optionBuilder, int offset);
452 
453  TLVRecordReader<DhcpV6Option> m_OptionReader;
454  };
455 
456  // implementation of inline methods
457 
458  bool DhcpV6Layer::isDhcpV6Port(uint16_t port)
459  {
460  return (port == 546) || (port == 547);
461  }
462 
463  bool DhcpV6Layer::isDataValid(const uint8_t* data, size_t dataLen)
464  {
465  return data && dataLen >= sizeof(dhcpv6_header);
466  }
467 
468 } // namespace pcpp
Definition: DhcpV6Layer.h:285
std::string toString() const
std::string getMessageTypeAsString() const
DhcpV6Option getNextOptionData(DhcpV6Option dhcpv6Option) const
DhcpV6Option addOptionAfter(const DhcpV6OptionBuilder &optionBuilder, DhcpV6OptionType optionType)
bool removeOption(DhcpV6OptionType optionType)
void setMessageType(DhcpV6MessageType messageType)
DhcpV6Option addOptionBefore(const DhcpV6OptionBuilder &optionBuilder, DhcpV6OptionType optionType)
DhcpV6Layer(DhcpV6MessageType messageType, uint32_t transactionId)
OsiModelLayer getOsiModelLayer() const
Definition: DhcpV6Layer.h:437
void computeCalculateFields()
Definition: DhcpV6Layer.h:432
void setTransactionID(uint32_t transactionId) const
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:463
DhcpV6Option getFirstOptionData() const
DhcpV6Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
void parseNextLayer()
Definition: DhcpV6Layer.h:418
size_t getHeaderLen() const
Definition: DhcpV6Layer.h:424
DhcpV6MessageType getMessageType() const
DhcpV6Option addOption(const DhcpV6OptionBuilder &optionBuilder)
static bool isDhcpV6Port(uint16_t port)
Definition: DhcpV6Layer.h:458
Definition: DhcpV6Layer.h:233
DhcpV6Option build() const
DhcpV6OptionBuilder(DhcpV6OptionType optionType, const std::string &optionValueAsHexStream)
Definition: DhcpV6Layer.h:241
DhcpV6OptionBuilder(DhcpV6OptionType optionType, const uint8_t *optionValue, uint8_t optionValueLen)
Definition: DhcpV6Layer.h:253
Definition: DhcpV6Layer.h:196
size_t getDataSize() const
std::string getValueAsHexString() const
size_t getTotalSize() const
DhcpV6Option(uint8_t *optionRawData)
Definition: DhcpV6Layer.h:202
DhcpV6OptionType getType() const
virtual ~DhcpV6Option()
Definition: DhcpV6Layer.h:208
Definition: Layer.h:70
Definition: Packet.h:27
Definition: TLVData.h:413
Definition: TLVData.h:23
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelApplicationLayer
Definition: ProtocolType.h:368
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:269
uint8_t messageType
Definition: DhcpV6Layer.h:271
uint8_t transactionId3
Definition: DhcpV6Layer.h:277
uint8_t transactionId2
Definition: DhcpV6Layer.h:275
uint8_t transactionId1
Definition: DhcpV6Layer.h:273