PcapPlusPlus  Next
IcmpV6Layer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 
6 
9 namespace pcpp
10 {
12  enum class ICMPv6MessageType : int
13  {
31  ICMPv6_ECHO_REQUEST = 128,
33  ICMPv6_ECHO_REPLY = 129,
90  };
91 
94 #pragma pack(push, 1)
95  struct icmpv6hdr
96  {
99  uint8_t type;
101  uint8_t code;
103  uint16_t checksum;
104  };
105 #pragma pack(pop)
106  static_assert(sizeof(icmpv6hdr) == 4, "icmpv6hdr size is not 4 bytes");
107 
110 #pragma pack(push, 1)
111  typedef struct icmpv6_echo_hdr : icmpv6hdr
112  {
114  uint16_t id;
116  uint16_t sequence;
117  } icmpv6_echo_hdr;
118 #pragma pack(pop)
119  static_assert(sizeof(icmpv6_echo_hdr) == 8, "icmpv6_echo_hdr size is not 8 bytes");
120 
123  class IcmpV6Layer : public Layer
124  {
125  public:
131  IcmpV6Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
132  : Layer(data, dataLen, prevLayer, packet, ICMPv6)
133  {}
134 
140  IcmpV6Layer(ICMPv6MessageType msgType, uint8_t code, const uint8_t* data, size_t dataLen);
141 
142  ~IcmpV6Layer() override = default;
143 
150  static Layer* parseIcmpV6Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
151 
155  {
156  return getMessageType() == type;
157  }
158 
161 
163  uint8_t getCode() const;
164 
166  uint16_t getChecksum() const;
167 
169  void parseNextLayer() override
170  {}
171 
173  size_t getHeaderLen() const override
174  {
175  return m_DataLen;
176  }
177 
179  void computeCalculateFields() override;
180 
182  {
183  return OsiModelNetworkLayer;
184  }
185 
186  std::string toString() const override;
187 
188  protected:
189  IcmpV6Layer() = default;
190 
191  private:
192  void calculateChecksum();
193  icmpv6hdr* getIcmpv6Header() const
194  {
195  return reinterpret_cast<icmpv6hdr*>(m_Data);
196  }
197  };
198 
202  {
203  public:
206  {
210  REPLY
211  };
212 
218  ICMPv6EchoLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
219  : IcmpV6Layer(data, dataLen, prevLayer, packet)
220  {}
221 
228  ICMPv6EchoLayer(ICMPv6EchoType echoType, uint16_t id, uint16_t sequence, const uint8_t* data, size_t dataLen);
229 
230  ~ICMPv6EchoLayer() override = default;
231 
233  uint16_t getIdentifier() const;
234 
236  uint16_t getSequenceNr() const;
237 
239  size_t getEchoDataLen() const
240  {
241  return m_DataLen - sizeof(icmpv6_echo_hdr);
242  }
243 
245  uint8_t* getEchoDataPtr() const
246  {
247  return m_Data + sizeof(icmpv6_echo_hdr);
248  }
249 
250  std::string toString() const override;
251 
252  private:
253  icmpv6_echo_hdr* getEchoHeader() const
254  {
255  return reinterpret_cast<icmpv6_echo_hdr*>(m_Data);
256  }
257  };
258 
259 } // namespace pcpp
Definition: IcmpV6Layer.h:202
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:245
ICMPv6EchoLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IcmpV6Layer.h:218
size_t getEchoDataLen() const
Definition: IcmpV6Layer.h:239
std::string toString() const override
ICMPv6EchoType
An enum representing ICMPv6 echo message types.
Definition: IcmpV6Layer.h:206
@ REQUEST
Echo Request Type.
Definition: IcmpV6Layer.h:208
@ REPLY
Echo Reply Type.
Definition: IcmpV6Layer.h:210
uint16_t getIdentifier() const
Definition: IcmpV6Layer.h:124
size_t getHeaderLen() const override
Definition: IcmpV6Layer.h:173
void computeCalculateFields() override
Calculate ICMPv6 checksum field.
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:131
uint8_t getCode() const
bool isMessageOfType(ICMPv6MessageType type) const
Definition: IcmpV6Layer.h:154
OsiModelLayer getOsiModelLayer() const override
Definition: IcmpV6Layer.h:181
std::string toString() const override
ICMPv6MessageType getMessageType() const
IcmpV6Layer(ICMPv6MessageType msgType, uint8_t code, const uint8_t *data, size_t dataLen)
void parseNextLayer() override
Does nothing for this layer. ICMPv6 is the last layer.
Definition: IcmpV6Layer.h:169
uint16_t getChecksum() const
Definition: Layer.h:60
Definition: Packet.h:22
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
An enum representing OSI model layers.
Definition: ProtocolType.h:225
@ OsiModelNetworkLayer
Network layer (layer 3)
Definition: ProtocolType.h:231
ICMPv6MessageType
An enum representing the available ICMPv6 message types.
Definition: IcmpV6Layer.h:13
@ ICMPv6_HOME_AGENT_ADDRESS_DISCOVERY_REQUEST_MESSAGE
Home Agent Address Discovery Request Message.
@ ICMPv6_PRIVATE_EXPERIMENTATION3
Private Experimentation Message.
@ ICMPv6_MOBILE_PREFIX_SOLICITATION
Mobile Prefix Solicitation Message.
@ ICMPv6_HOME_AGENT_ADDRESS_DISCOVERY_REPLY_MESSAGE
Home Agent Address Discovery Reply Message.
@ ICMPv6_ICMP_NODE_INFORMATION_QUERY
Node Information Query Message.
@ ICMPv6_MULTICAST_ROUTER_ADVERTISEMENT
Multicast Router Advertisement Message.
@ ICMPv6_CERTIFICATION_PATH_ADVERTISEMENT
Certification Path Advertisement Message.
@ ICMPv6_REDIRECT_MESSAGE
Redirect Message.
@ ICMPv6_PRIVATE_EXPERIMENTATION4
Private Experimentation Message.
@ ICMPv6_NEIGHBOR_ADVERTISEMENT
Neighbor Advertisement Message.
@ ICMPv6_EXPERIMENTAL_MOBILITY
ICMP Experimental Mobility Subtype Format and Registry Message.
@ ICMPv6_TIME_EXCEEDED
Time Exceeded Message.
@ ICMPv6_ROUTER_SOLICITATION
Router Solicitation Message.
@ ICMPv6_PACKET_TOO_BIG
Packet Too Big Message.
@ ICMPv6_ROUTER_RENUMBERING
Router Renumbering Message.
@ ICMPv6_PRIVATE_EXPERIMENTATION2
Private Experimentation Message.
@ ICMPv6_ECHO_REQUEST
Echo Request Message.
@ ICMPv6_MULTICAST_LISTENER_QUERY
Multicast Listener Query Message.
@ ICMPv6_INVERSE_NEIGHBOR_DISCOVERY_SOLICITATION_MESSAGE
Inverse Neighbor Discovery Solicitation Message.
@ ICMPv6_ROUTER_ADVERTISEMENT
Router Advertisement Message.
@ ICMPv6_MULTICAST_LISTENER_DISCOVERY_REPORTS
Multicast Listener Report Message.
@ ICMPv6_MULTICAST_LISTENER_REPORT
Multicast Listener Report Message.
@ ICMPv6_DESTINATION_UNREACHABLE
Destination Unreachable Message.
@ ICMPv6_MOBILE_PREFIX_ADVERTISEMENT
Mobile Prefix Advertisement Message.
@ ICMPv6_RESERVED_EXPANSION_INFORMATIONAL
Reserved for expansion of ICMPv6 informational messages.
@ ICMPv6_NEIGHBOR_SOLICITATION
Neighbor Solicitation Message.
@ ICMPv6_CERTIFICATION_PATH_SOLICITATION
Certification Path Solicitation Message.
@ ICMPv6_MULTICAST_LISTENER_DONE
Multicast Listener Done Message.
@ ICMPv6_UNKNOWN_MESSAGE
Unknown ICMPv6 message.
@ ICMPv6_PARAMETER_PROBLEM
Parameter Problem Message.
@ ICMPv6_RPL_CONTROL_MESSAGE
RPL Control Message.
@ ICMPv6_MULTICAST_ROUTER_SOLICITATION
Multicast Router Solicitation Message.
@ ICMPv6_PRIVATE_EXPERIMENTATION1
Private Experimentation Message.
@ ICMPv6_INVERSE_NEIGHBOR_DISCOVERY_ADVERTISEMENT_MESSAGE
Inverse Neighbor Discovery Advertisement Message.
@ ICMPv6_ECHO_REPLY
Echo Reply Message.
@ ICMPv6_MULTICAST_ROUTER_TERMINATION
Multicast Router Termination Message.
@ ICMPv6_RESERVED_EXPANSION_ERROR
Reserved for expansion of ICMPv6 error messages.
@ ICMPv6_ICMP_NODE_INFORMATION_RESPONSE
Node Information Reply Message.
const ProtocolType ICMPv6
ICMPv6 protocol.
Definition: ProtocolType.h:170
Definition: IcmpV6Layer.h:112
uint16_t id
the echo request identifier
Definition: IcmpV6Layer.h:114
uint16_t sequence
the echo request sequence number
Definition: IcmpV6Layer.h:116
Definition: IcmpV6Layer.h:96
uint16_t checksum
The checksum field provides a minimal level of integrity verification for the ICMP message.
Definition: IcmpV6Layer.h:103
uint8_t type
Definition: IcmpV6Layer.h:99
uint8_t code
The code field value depends on the message type and provides an additional level of message granular...
Definition: IcmpV6Layer.h:101