PcapPlusPlus  23.09
IcmpV6Layer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_ICMPV6_LAYER
2 #define PACKETPP_ICMPV6_LAYER
3 
4 #include "Layer.h"
5 
7 
12 namespace pcpp
13 {
14 
18 enum class ICMPv6MessageType : int
19 {
37  ICMPv6_ECHO_REQUEST = 128,
39  ICMPv6_ECHO_REPLY = 129,
96 };
97 
102 #pragma pack(push, 1)
103 struct icmpv6hdr
104 {
107  uint8_t type;
109  uint8_t code;
111  uint16_t checksum;
112 };
113 #pragma pack(pop)
114 
119 #pragma pack(push, 1)
120 typedef struct icmpv6_echo_hdr : icmpv6hdr
121 {
123  uint16_t id;
125  uint16_t sequence;
127 #pragma pack(pop)
128 
133 class IcmpV6Layer : public Layer
134 {
135 public:
143  IcmpV6Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
144  : Layer(data, dataLen, prevLayer, packet) { m_Protocol = ICMPv6; }
145 
153  IcmpV6Layer(ICMPv6MessageType msgType, uint8_t code, const uint8_t *data, size_t dataLen);
154 
155  virtual ~IcmpV6Layer() {}
156 
165  static Layer *parseIcmpV6Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet);
166 
171  bool isMessageOfType(ICMPv6MessageType type) const { return getMessageType() == type; }
172 
176  ICMPv6MessageType getMessageType() const;
177 
181  uint8_t getCode() const;
182 
186  uint16_t getChecksum() const;
187 
191  void parseNextLayer() {}
192 
196  size_t getHeaderLen() const { return m_DataLen; }
197 
201  void computeCalculateFields();
202 
204 
205  std::string toString() const;
206 
207 protected:
208  IcmpV6Layer() = default;
209 
210 private:
211  void calculateChecksum();
212  icmpv6hdr *getIcmpv6Header() const { return (icmpv6hdr *)m_Data; }
213 };
214 
220 {
221 public:
226  {
230  REPLY
231  };
232 
240  ICMPv6EchoLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
241  : IcmpV6Layer(data, dataLen, prevLayer, packet) {}
242 
251  ICMPv6EchoLayer(ICMPv6EchoType echoType, uint16_t id, uint16_t sequence, const uint8_t *data, size_t dataLen);
252 
253  virtual ~ICMPv6EchoLayer() {}
254 
258  uint16_t getIdentifier() const;
259 
263  uint16_t getSequenceNr() const;
264 
268  size_t getEchoDataLen() const { return m_DataLen - sizeof(icmpv6_echo_hdr); }
269 
273  uint8_t *getEchoDataPtr() const { return m_Data + sizeof(icmpv6_echo_hdr); }
274 
275  std::string toString() const;
276 
277 private:
278  icmpv6_echo_hdr *getEchoHeader() const { return (icmpv6_echo_hdr *)m_Data; }
279 };
280 
281 } // namespace pcpp
282 #endif /* PACKETPP_ICMPV6_LAYER */
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:333
Definition: IcmpV6Layer.h:133
uint16_t sequence
Definition: IcmpV6Layer.h:125
size_t getHeaderLen() const
Definition: IcmpV6Layer.h:196
Definition: Layer.h:70
Definition: Packet.h:26
Definition: IcmpV6Layer.h:103
IcmpV6Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IcmpV6Layer.h:143
uint8_t code
Definition: IcmpV6Layer.h:109
Definition: ProtocolType.h:340
ICMPv6MessageType
Definition: IcmpV6Layer.h:18
Definition: IcmpV6Layer.h:228
size_t getEchoDataLen() const
Definition: IcmpV6Layer.h:268
ICMPv6EchoLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IcmpV6Layer.h:240
uint8_t type
Definition: IcmpV6Layer.h:107
Definition: IcmpV6Layer.h:219
bool isMessageOfType(ICMPv6MessageType type) const
Definition: IcmpV6Layer.h:171
Definition: IcmpV6Layer.h:120
uint16_t id
Definition: IcmpV6Layer.h:123
void parseNextLayer()
Definition: IcmpV6Layer.h:191
ICMPv6EchoType
Definition: IcmpV6Layer.h:225
const ProtocolType ICMPv6
Definition: ProtocolType.h:273
OsiModelLayer getOsiModelLayer() const
Definition: IcmpV6Layer.h:203
uint8_t * getEchoDataPtr() const
Definition: IcmpV6Layer.h:273
uint16_t checksum
Definition: IcmpV6Layer.h:111