PcapPlusPlus  24.09
IcmpV6Layer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 
6 
11 namespace pcpp
12 {
13 
17  enum class ICMPv6MessageType : int
18  {
36  ICMPv6_ECHO_REQUEST = 128,
38  ICMPv6_ECHO_REPLY = 129,
95  };
96 
101 #pragma pack(push, 1)
102  struct icmpv6hdr
103  {
106  uint8_t type;
108  uint8_t code;
110  uint16_t checksum;
111  };
112 #pragma pack(pop)
113 
118 #pragma pack(push, 1)
119  typedef struct icmpv6_echo_hdr : icmpv6hdr
120  {
122  uint16_t id;
124  uint16_t sequence;
125  } icmpv6_echo_hdr;
126 #pragma pack(pop)
127 
132  class IcmpV6Layer : public Layer
133  {
134  public:
142  IcmpV6Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
143  : Layer(data, dataLen, prevLayer, packet, ICMPv6)
144  {}
145 
153  IcmpV6Layer(ICMPv6MessageType msgType, uint8_t code, const uint8_t* data, size_t dataLen);
154 
155  virtual ~IcmpV6Layer()
156  {}
157 
166  static Layer* parseIcmpV6Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
167 
173  {
174  return getMessageType() == type;
175  }
176 
181 
185  uint8_t getCode() const;
186 
190  uint16_t getChecksum() const;
191 
196  {}
197 
201  size_t getHeaderLen() const
202  {
203  return m_DataLen;
204  }
205 
210 
212  {
213  return OsiModelNetworkLayer;
214  }
215 
216  std::string toString() const;
217 
218  protected:
219  IcmpV6Layer() = default;
220 
221  private:
222  void calculateChecksum();
223  icmpv6hdr* getIcmpv6Header() const
224  {
225  return (icmpv6hdr*)m_Data;
226  }
227  };
228 
234  {
235  public:
240  {
244  REPLY
245  };
246 
254  ICMPv6EchoLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
255  : IcmpV6Layer(data, dataLen, prevLayer, packet)
256  {}
257 
266  ICMPv6EchoLayer(ICMPv6EchoType echoType, uint16_t id, uint16_t sequence, const uint8_t* data, size_t dataLen);
267 
268  virtual ~ICMPv6EchoLayer()
269  {}
270 
274  uint16_t getIdentifier() const;
275 
279  uint16_t getSequenceNr() const;
280 
284  size_t getEchoDataLen() const
285  {
286  return m_DataLen - sizeof(icmpv6_echo_hdr);
287  }
288 
292  uint8_t* getEchoDataPtr() const
293  {
294  return m_Data + sizeof(icmpv6_echo_hdr);
295  }
296 
297  std::string toString() const;
298 
299  private:
300  icmpv6_echo_hdr* getEchoHeader() const
301  {
302  return (icmpv6_echo_hdr*)m_Data;
303  }
304  };
305 
306 } // namespace pcpp
Definition: IcmpV6Layer.h:234
ICMPv6EchoLayer(ICMPv6EchoType echoType, uint16_t id, uint16_t sequence, const uint8_t *data, size_t dataLen)
uint16_t getSequenceNr() const
std::string toString() const
uint8_t * getEchoDataPtr() const
Definition: IcmpV6Layer.h:292
ICMPv6EchoLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IcmpV6Layer.h:254
size_t getEchoDataLen() const
Definition: IcmpV6Layer.h:284
ICMPv6EchoType
Definition: IcmpV6Layer.h:240
@ REQUEST
Definition: IcmpV6Layer.h:242
@ REPLY
Definition: IcmpV6Layer.h:244
uint16_t getIdentifier() const
Definition: IcmpV6Layer.h:133
size_t getHeaderLen() const
Definition: IcmpV6Layer.h:201
static Layer * parseIcmpV6Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
void computeCalculateFields()
IcmpV6Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IcmpV6Layer.h:142
OsiModelLayer getOsiModelLayer() const
Definition: IcmpV6Layer.h:211
uint8_t getCode() const
bool isMessageOfType(ICMPv6MessageType type) const
Definition: IcmpV6Layer.h:172
std::string toString() const
ICMPv6MessageType getMessageType() const
void parseNextLayer()
Definition: IcmpV6Layer.h:195
IcmpV6Layer(ICMPv6MessageType msgType, uint8_t code, const uint8_t *data, size_t dataLen)
uint16_t getChecksum() const
Definition: Layer.h:70
Definition: Packet.h:27
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelNetworkLayer
Definition: ProtocolType.h:360
ICMPv6MessageType
Definition: IcmpV6Layer.h:18
@ ICMPv6_HOME_AGENT_ADDRESS_DISCOVERY_REQUEST_MESSAGE
@ ICMPv6_HOME_AGENT_ADDRESS_DISCOVERY_REPLY_MESSAGE
@ ICMPv6_INVERSE_NEIGHBOR_DISCOVERY_SOLICITATION_MESSAGE
@ ICMPv6_INVERSE_NEIGHBOR_DISCOVERY_ADVERTISEMENT_MESSAGE
const ProtocolType ICMPv6
Definition: ProtocolType.h:278
Definition: IcmpV6Layer.h:120
uint16_t id
Definition: IcmpV6Layer.h:122
uint16_t sequence
Definition: IcmpV6Layer.h:124
Definition: IcmpV6Layer.h:103
uint16_t checksum
Definition: IcmpV6Layer.h:110
uint8_t type
Definition: IcmpV6Layer.h:106
uint8_t code
Definition: IcmpV6Layer.h:108