PcapPlusPlus  Next
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  ~IcmpV6Layer() override = default;
156 
165  static Layer* parseIcmpV6Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
166 
172  {
173  return getMessageType() == type;
174  }
175 
180 
184  uint8_t getCode() const;
185 
189  uint16_t getChecksum() const;
190 
194  void parseNextLayer() override
195  {}
196 
200  size_t getHeaderLen() const override
201  {
202  return m_DataLen;
203  }
204 
208  void computeCalculateFields() override;
209 
211  {
212  return OsiModelNetworkLayer;
213  }
214 
215  std::string toString() const override;
216 
217  protected:
218  IcmpV6Layer() = default;
219 
220  private:
221  void calculateChecksum();
222  icmpv6hdr* getIcmpv6Header() const
223  {
224  return reinterpret_cast<icmpv6hdr*>(m_Data);
225  }
226  };
227 
233  {
234  public:
239  {
243  REPLY
244  };
245 
253  ICMPv6EchoLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
254  : IcmpV6Layer(data, dataLen, prevLayer, packet)
255  {}
256 
265  ICMPv6EchoLayer(ICMPv6EchoType echoType, uint16_t id, uint16_t sequence, const uint8_t* data, size_t dataLen);
266 
267  ~ICMPv6EchoLayer() override = default;
268 
272  uint16_t getIdentifier() const;
273 
277  uint16_t getSequenceNr() const;
278 
282  size_t getEchoDataLen() const
283  {
284  return m_DataLen - sizeof(icmpv6_echo_hdr);
285  }
286 
290  uint8_t* getEchoDataPtr() const
291  {
292  return m_Data + sizeof(icmpv6_echo_hdr);
293  }
294 
295  std::string toString() const override;
296 
297  private:
298  icmpv6_echo_hdr* getEchoHeader() const
299  {
300  return reinterpret_cast<icmpv6_echo_hdr*>(m_Data);
301  }
302  };
303 
304 } // namespace pcpp
Definition: IcmpV6Layer.h:233
ICMPv6EchoLayer(ICMPv6EchoType echoType, uint16_t id, uint16_t sequence, const uint8_t *data, size_t dataLen)
uint16_t getSequenceNr() const
uint8_t * getEchoDataPtr() const
Definition: IcmpV6Layer.h:290
ICMPv6EchoLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IcmpV6Layer.h:253
size_t getEchoDataLen() const
Definition: IcmpV6Layer.h:282
std::string toString() const override
ICMPv6EchoType
Definition: IcmpV6Layer.h:239
@ REQUEST
Definition: IcmpV6Layer.h:241
@ REPLY
Definition: IcmpV6Layer.h:243
uint16_t getIdentifier() const
Definition: IcmpV6Layer.h:133
size_t getHeaderLen() const override
Definition: IcmpV6Layer.h:200
void computeCalculateFields() override
static Layer * parseIcmpV6Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
IcmpV6Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IcmpV6Layer.h:142
uint8_t getCode() const
bool isMessageOfType(ICMPv6MessageType type) const
Definition: IcmpV6Layer.h:171
OsiModelLayer getOsiModelLayer() const override
Definition: IcmpV6Layer.h:210
std::string toString() const override
ICMPv6MessageType getMessageType() const
IcmpV6Layer(ICMPv6MessageType msgType, uint8_t code, const uint8_t *data, size_t dataLen)
void parseNextLayer() override
Definition: IcmpV6Layer.h:194
uint16_t getChecksum() const
Definition: Layer.h:69
Definition: Packet.h:27
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:364
@ OsiModelNetworkLayer
Definition: ProtocolType.h:370
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