PcapPlusPlus  19.12
IcmpLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_ICMP_LAYER
2 #define PACKETPP_ICMP_LAYER
3 
4 #include "Layer.h"
5 #include "IPv4Layer.h"
6 #ifdef _MSC_VER
7 #include <Winsock2.h>
8 #else
9 #include <sys/time.h>
10 #endif
11 #include <vector>
12 
13 
15 
20 namespace pcpp
21 {
22 
27 #pragma pack(push, 1)
28  typedef struct
29  {
31  uint8_t type;
33  uint8_t code;
35  uint16_t checksum;
36  } icmphdr;
37 #pragma pack(pop)
38 
43  {
76  };
77 
83  {
122  };
123 
124 
129 #pragma pack(push, 1)
130  typedef struct : icmphdr
131  {
133  uint16_t id;
135  uint16_t sequence;
137  uint64_t timestamp;
138  } icmp_echo_hdr;
139 #pragma pack(pop)
140 
141 
146  typedef struct
147  {
151  size_t dataLength;
153  uint8_t* data;
155 
156 
162 
163 
168 #pragma pack(push, 1)
169  typedef struct : icmphdr
170  {
172  uint16_t id;
174  uint16_t sequence;
182 #pragma pack(pop)
183 
184 
190 
191 
196 #pragma pack(push, 1)
197  typedef struct : icmphdr
198  {
200  uint16_t unused;
202  uint16_t nextHopMTU;
204 #pragma pack(pop)
205 
206 
211 #pragma pack(push, 1)
212  typedef struct : icmphdr
213  {
215  uint32_t unused;
217 #pragma pack(pop)
218 
219 
225 
226 
231 #pragma pack(push, 1)
232  typedef struct : icmphdr
233  {
235  uint8_t pointer;
237  uint8_t unused1;
239  uint16_t unused2;
241 #pragma pack(pop)
242 
243 
249 
254 #pragma pack(push, 1)
255  typedef struct : icmphdr
256  {
258  uint32_t gatewayAddress;
259  } icmp_redirect;
260 #pragma pack(pop)
261 
262 
267 #pragma pack(push, 1)
269  {
271  uint32_t routerAddress;
275  uint32_t preferenceLevel;
276 
282  void setRouterAddress(IPv4Address addr, uint32_t preference);
283 
288  };
289 #pragma pack(pop)
290 
291 
296 #pragma pack(push, 1)
297  typedef struct : icmphdr
298  {
305  uint16_t lifetime;
307 #pragma pack(pop)
308 
309 
315  {
318 
326  };
327 
328 
333 #pragma pack(push, 1)
334  typedef struct : icmphdr
335  {
337  uint16_t id;
339  uint16_t sequence;
341  uint32_t addressMask;
343 #pragma pack(pop)
344 
345 
351 
352 
357 #pragma pack(push, 1)
358  typedef struct : icmphdr
359  {
361  uint16_t id;
363  uint16_t sequence;
365 #pragma pack(pop)
366 
367 
373 
374 
379  class IcmpLayer : public Layer
380  {
381  private:
382  icmp_echo_request m_EchoData;
383  mutable icmp_router_advertisement m_RouterAdvData;
384 
385  bool cleanIcmpLayer();
386 
387  bool setEchoData(IcmpMessageType echoType, uint16_t id, uint16_t sequence, uint64_t timestamp, const uint8_t* data, size_t dataLen);
388 
389  bool setIpAndL4Layers(IPv4Layer* ipLayer, Layer* l4Layer);
390 
391  public:
399  IcmpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = ICMP; }
400 
405  IcmpLayer();
406 
407  virtual ~IcmpLayer() {}
408 
413  icmphdr* getIcmpHeader() const { return (icmphdr*)m_Data; }
414 
419 
424  bool isMessageOfType(IcmpMessageType type) const;
425 
430 
441  icmp_echo_request* setEchoRequestData(uint16_t id, uint16_t sequence, uint64_t timestamp, const uint8_t* data, size_t dataLen);
442 
447 
458  icmp_echo_reply* setEchoReplyData(uint16_t id, uint16_t sequence, uint64_t timestamp, const uint8_t* data, size_t dataLen);
459 
464 
473  icmp_timestamp_request* setTimestampRequestData(uint16_t id, uint16_t sequence, timeval originateTimestamp);
474 
479 
490  icmp_timestamp_reply* setTimestampReplyData(uint16_t id, uint16_t sequence,
491  timeval originateTimestamp, timeval receiveTimestamp, timeval transmitTimestamp);
492 
499 
511  icmp_destination_unreachable* setDestUnreachableData(IcmpDestUnreachableCodes code, uint16_t nextHopMTU, IPv4Layer* ipHeader, Layer* l4Header);
512 
519 
529  icmp_source_quench* setSourceQuenchdata(IPv4Layer* ipHeader, Layer* l4Header);
530 
537 
549  icmp_redirect* setRedirectData(uint8_t code, IPv4Address gatewayAddress, IPv4Layer* ipHeader, Layer* l4Header);
550 
555 
564  icmp_router_advertisement* setRouterAdvertisementData(uint8_t code, uint16_t lifetimeInSeconds, const std::vector<icmp_router_address_structure>& routerAddresses);
565 
570 
578 
585 
596  icmp_time_exceeded* setTimeExceededData(uint8_t code, IPv4Layer* ipHeader, Layer* l4Header);
597 
602 
614  icmp_param_problem* setParamProblemData(uint8_t code, uint8_t errorOctetPointer, IPv4Layer* ipHeader, Layer* l4Header);
615 
620 
629  icmp_address_mask_request* setAddressMaskRequestData(uint16_t id, uint16_t sequence, IPv4Address mask);
630 
635 
644  icmp_address_mask_reply* setAddressMaskReplyData(uint16_t id, uint16_t sequence, IPv4Address mask);
645 
650 
658  icmp_info_request* setInfoRequestData(uint16_t id, uint16_t sequence);
659 
664 
672  icmp_info_reply* setInfoReplyData(uint16_t id, uint16_t sequence);
673 
674 
675  // implement abstract methods
676 
682  void parseNextLayer();
683 
689  size_t getHeaderLen() const;
690 
694  void computeCalculateFields();
695 
696  std::string toString() const;
697 
699  };
700 
701 } // namespace pcpp
702 
703 #endif /* PACKETPP_ICMP_LAYER */
pcpp::icmp_param_problem::pointer
uint8_t pointer
Definition: IcmpLayer.h:235
pcpp::IcmpLayer::IcmpLayer
IcmpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IcmpLayer.h:399
pcpp::IcmpLayer::setParamProblemData
icmp_param_problem * setParamProblemData(uint8_t code, uint8_t errorOctetPointer, IPv4Layer *ipHeader, Layer *l4Header)
pcpp::icmp_timestamp_request::sequence
uint16_t sequence
Definition: IcmpLayer.h:174
pcpp::OsiModelLayer
OsiModelLayer
Definition: ProtocolType.h:224
pcpp::IPv4Address
Definition: IpAddress.h:119
pcpp::icmphdr
Definition: IcmpLayer.h:28
pcpp::Packet
Definition: Packet.h:26
pcpp::ICMP_ECHO_REQUEST
Definition: IcmpLayer.h:53
pcpp::icmp_address_mask_request
Definition: IcmpLayer.h:334
pcpp::IcmpLayer::setRouterAdvertisementData
icmp_router_advertisement * setRouterAdvertisementData(uint8_t code, uint16_t lifetimeInSeconds, const std::vector< icmp_router_address_structure > &routerAddresses)
pcpp::icmp_router_solicitation
icmphdr icmp_router_solicitation
Definition: IcmpLayer.h:248
pcpp::IcmpLayer::toString
std::string toString() const
pcpp::ICMP_TIMESTAMP_REQUEST
Definition: IcmpLayer.h:63
pcpp::icmp_router_address_structure
Definition: IcmpLayer.h:268
Layer.h
pcpp::ICMP_INFO_REPLY
Definition: IcmpLayer.h:69
pcpp::IcmpDestUnreachableCodes
IcmpDestUnreachableCodes
Definition: IcmpLayer.h:82
pcpp::ICMP_ROUTER_SOL
Definition: IcmpLayer.h:57
pcpp::ICMP_TIME_EXCEEDED
Definition: IcmpLayer.h:59
pcpp::icmphdr::checksum
uint16_t checksum
Definition: IcmpLayer.h:35
pcpp::icmp_timestamp_request
Definition: IcmpLayer.h:169
pcpp::icmp_router_advertisement_hdr
Definition: IcmpLayer.h:297
pcpp::icmp_source_quench
icmp_time_exceeded icmp_source_quench
Definition: IcmpLayer.h:224
pcpp::icmp_router_advertisement::header
icmp_router_advertisement_hdr * header
Definition: IcmpLayer.h:317
pcpp::IcmpLayer
Definition: IcmpLayer.h:379
pcpp::icmp_timestamp_reply
icmp_timestamp_request icmp_timestamp_reply
Definition: IcmpLayer.h:189
pcpp::icmp_destination_unreachable
Definition: IcmpLayer.h:197
pcpp::icmp_router_advertisement_hdr::advertisementCount
uint8_t advertisementCount
Definition: IcmpLayer.h:300
pcpp::icmp_address_mask_request::id
uint16_t id
Definition: IcmpLayer.h:337
pcpp::icmp_echo_request::header
icmp_echo_hdr * header
Definition: IcmpLayer.h:149
pcpp::IcmpLayer::setRouterSolicitationData
icmp_router_solicitation * setRouterSolicitationData()
pcpp::IPv4Layer
Definition: IPv4Layer.h:405
pcpp::icmp_router_advertisement::getRouterAddress
icmp_router_address_structure * getRouterAddress(int index) const
pcpp::IcmpLayer::setRedirectData
icmp_redirect * setRedirectData(uint8_t code, IPv4Address gatewayAddress, IPv4Layer *ipHeader, Layer *l4Header)
pcpp::ICMP_SOURCE_QUENCH
Definition: IcmpLayer.h:49
pcpp::IcmpLayer::getTimestampReplyData
icmp_timestamp_reply * getTimestampReplyData()
pcpp::icmp_redirect
Definition: IcmpLayer.h:255
pcpp::icmp_echo_hdr::timestamp
uint64_t timestamp
Definition: IcmpLayer.h:137
pcpp::icmp_echo_reply
icmp_echo_request icmp_echo_reply
Definition: IcmpLayer.h:161
pcpp::icmp_router_address_structure::preferenceLevel
uint32_t preferenceLevel
Definition: IcmpLayer.h:275
pcpp::OsiModelNetworkLayer
Definition: ProtocolType.h:231
pcpp::icmp_param_problem
Definition: IcmpLayer.h:232
pcpp::IcmpLayer::setAddressMaskRequestData
icmp_address_mask_request * setAddressMaskRequestData(uint16_t id, uint16_t sequence, IPv4Address mask)
pcpp::icmp_time_exceeded
Definition: IcmpLayer.h:212
pcpp::icmp_timestamp_request::receiveTimestamp
uint32_t receiveTimestamp
Definition: IcmpLayer.h:178
pcpp::icmp_echo_hdr::sequence
uint16_t sequence
Definition: IcmpLayer.h:135
pcpp::ICMP_ADDRESS_MASK_REPLY
Definition: IcmpLayer.h:73
pcpp::IcmpLayer::getEchoReplyData
icmp_echo_reply * getEchoReplyData()
pcpp::icmp_router_address_structure::routerAddress
uint32_t routerAddress
Definition: IcmpLayer.h:271
pcpp::icmp_router_advertisement_hdr::lifetime
uint16_t lifetime
Definition: IcmpLayer.h:305
pcpp::IcmpLayer::getAddressMaskRequestData
icmp_address_mask_request * getAddressMaskRequestData()
pcpp::icmp_echo_request
Definition: IcmpLayer.h:146
pcpp::icmp_echo_hdr
Definition: IcmpLayer.h:130
pcpp::icmp_destination_unreachable::unused
uint16_t unused
Definition: IcmpLayer.h:200
pcpp::IcmpNetworkUnreachable
Definition: IcmpLayer.h:85
pcpp::icmp_router_address_structure::setRouterAddress
void setRouterAddress(IPv4Address addr, uint32_t preference)
pcpp::IcmpLayer::getEchoRequestData
icmp_echo_request * getEchoRequestData()
pcpp::IcmpLayer::setInfoReplyData
icmp_info_reply * setInfoReplyData(uint16_t id, uint16_t sequence)
pcpp::ICMP_UNSUPPORTED
Definition: IcmpLayer.h:75
pcpp::IcmpLayer::setDestUnreachableData
icmp_destination_unreachable * setDestUnreachableData(IcmpDestUnreachableCodes code, uint16_t nextHopMTU, IPv4Layer *ipHeader, Layer *l4Header)
pcpp::IcmpLayer::getIcmpHeader
icmphdr * getIcmpHeader() const
Definition: IcmpLayer.h:413
pcpp::icmp_destination_unreachable::nextHopMTU
uint16_t nextHopMTU
Definition: IcmpLayer.h:202
pcpp::IcmpLayer::getHeaderLen
size_t getHeaderLen() const
pcpp::icmphdr::code
uint8_t code
Definition: IcmpLayer.h:33
pcpp::IcmpLayer::getRouterSolicitationData
icmp_router_solicitation * getRouterSolicitationData()
pcpp::icmp_param_problem::unused1
uint8_t unused1
Definition: IcmpLayer.h:237
pcpp::IcmpHostUnreachableForTypeOfService
Definition: IcmpLayer.h:109
pcpp::IcmpPortUnreachable
Definition: IcmpLayer.h:91
pcpp::ICMP_DEST_UNREACHABLE
Definition: IcmpLayer.h:47
pcpp::icmp_info_request::id
uint16_t id
Definition: IcmpLayer.h:361
pcpp::IcmpCommunicationProhibited
Definition: IcmpLayer.h:113
pcpp::IcmpLayer::getOsiModelLayer
OsiModelLayer getOsiModelLayer() const
Definition: IcmpLayer.h:698
pcpp::IcmpLayer::getSourceQuenchdata
icmp_source_quench * getSourceQuenchdata()
pcpp::IcmpLayer::getAddressMaskReplyData
icmp_address_mask_reply * getAddressMaskReplyData()
pcpp::IcmpDatagramTooBig
Definition: IcmpLayer.h:93
pcpp::IcmpLayer::setEchoRequestData
icmp_echo_request * setEchoRequestData(uint16_t id, uint16_t sequence, uint64_t timestamp, const uint8_t *data, size_t dataLen)
pcpp::IcmpLayer::setAddressMaskReplyData
icmp_address_mask_reply * setAddressMaskReplyData(uint16_t id, uint16_t sequence, IPv4Address mask)
pcpp::icmp_time_exceeded::unused
uint32_t unused
Definition: IcmpLayer.h:215
pcpp::IcmpSourceRouteFailed
Definition: IcmpLayer.h:95
pcpp::IcmpLayer::getDestUnreachableData
icmp_destination_unreachable * getDestUnreachableData()
pcpp::icmp_router_advertisement
Definition: IcmpLayer.h:314
pcpp::IcmpLayer::parseNextLayer
void parseNextLayer()
pcpp::IcmpLayer::setTimestampReplyData
icmp_timestamp_reply * setTimestampReplyData(uint16_t id, uint16_t sequence, timeval originateTimestamp, timeval receiveTimestamp, timeval transmitTimestamp)
pcpp::IcmpLayer::getRedirectData
icmp_redirect * getRedirectData()
pcpp::icmp_info_request
Definition: IcmpLayer.h:358
pcpp::ICMP_TIMESTAMP_REPLY
Definition: IcmpLayer.h:65
pcpp::IcmpLayer::setTimeExceededData
icmp_time_exceeded * setTimeExceededData(uint8_t code, IPv4Layer *ipHeader, Layer *l4Header)
pcpp::ICMP_INFO_REQUEST
Definition: IcmpLayer.h:67
pcpp::IcmpHostUnreachable
Definition: IcmpLayer.h:87
pcpp::icmp_echo_request::dataLength
size_t dataLength
Definition: IcmpLayer.h:151
pcpp::icmp_timestamp_request::originateTimestamp
uint32_t originateTimestamp
Definition: IcmpLayer.h:176
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::IcmpDestinationNetworkUnknown
Definition: IcmpLayer.h:97
pcpp::IcmpSourceHostIsolated
Definition: IcmpLayer.h:101
pcpp::IcmpLayer::getInfoReplyData
icmp_info_reply * getInfoReplyData()
pcpp::IcmpLayer::getRouterAdvertisementData
icmp_router_advertisement * getRouterAdvertisementData() const
pcpp::IcmpLayer::setInfoRequestData
icmp_info_request * setInfoRequestData(uint16_t id, uint16_t sequence)
pcpp::IcmpLayer::getParamProblemData
icmp_param_problem * getParamProblemData()
pcpp::ICMP_ECHO_REPLY
Definition: IcmpLayer.h:45
pcpp::icmp_info_request::sequence
uint16_t sequence
Definition: IcmpLayer.h:363
pcpp::Layer
Definition: Layer.h:70
pcpp::IcmpLayer::IcmpLayer
IcmpLayer()
pcpp::ICMP_ADDRESS_MASK_REQUEST
Definition: IcmpLayer.h:71
pcpp::icmp_router_address_structure::getAddress
IPv4Address getAddress()
pcpp::icmp_router_advertisement_hdr::addressEntrySize
uint8_t addressEntrySize
Definition: IcmpLayer.h:303
pcpp::IcmpLayer::getMessageType
IcmpMessageType getMessageType() const
pcpp::IcmpDestinationHostUnknown
Definition: IcmpLayer.h:99
pcpp::IcmpHostPrecedenceViolation
Definition: IcmpLayer.h:117
pcpp::icmphdr::type
uint8_t type
Definition: IcmpLayer.h:31
pcpp::icmp_param_problem::unused2
uint16_t unused2
Definition: IcmpLayer.h:239
pcpp::icmp_address_mask_reply
icmp_address_mask_request icmp_address_mask_reply
Definition: IcmpLayer.h:350
pcpp::icmp_redirect::gatewayAddress
uint32_t gatewayAddress
Definition: IcmpLayer.h:258
pcpp::IcmpPrecedenceCutoff
Definition: IcmpLayer.h:121
pcpp::icmp_address_mask_request::sequence
uint16_t sequence
Definition: IcmpLayer.h:339
pcpp::IcmpDestinationNetworkProhibited
Definition: IcmpLayer.h:103
pcpp::IcmpLayer::getTimeExceededData
icmp_time_exceeded * getTimeExceededData()
pcpp::IcmpLayer::setTimestampRequestData
icmp_timestamp_request * setTimestampRequestData(uint16_t id, uint16_t sequence, timeval originateTimestamp)
pcpp::IcmpLayer::setEchoReplyData
icmp_echo_reply * setEchoReplyData(uint16_t id, uint16_t sequence, uint64_t timestamp, const uint8_t *data, size_t dataLen)
pcpp::IcmpMessageType
IcmpMessageType
Definition: IcmpLayer.h:42
pcpp::icmp_address_mask_request::addressMask
uint32_t addressMask
Definition: IcmpLayer.h:341
pcpp::IcmpNetworkUnreachableForTypeOfService
Definition: IcmpLayer.h:107
pcpp::ICMP_REDIRECT
Definition: IcmpLayer.h:51
pcpp::ICMP_PARAM_PROBLEM
Definition: IcmpLayer.h:61
pcpp::icmp_timestamp_request::id
uint16_t id
Definition: IcmpLayer.h:172
pcpp::icmp_echo_hdr::id
uint16_t id
Definition: IcmpLayer.h:133
pcpp::ICMP_ROUTER_ADV
Definition: IcmpLayer.h:55
pcpp::IcmpLayer::setSourceQuenchdata
icmp_source_quench * setSourceQuenchdata(IPv4Layer *ipHeader, Layer *l4Header)
pcpp::icmp_info_reply
icmp_info_request icmp_info_reply
Definition: IcmpLayer.h:372
pcpp::IcmpLayer::getTimestampRequestData
icmp_timestamp_request * getTimestampRequestData()
pcpp::ICMP
Definition: ProtocolType.h:81
pcpp::icmp_timestamp_request::transmitTimestamp
uint32_t transmitTimestamp
Definition: IcmpLayer.h:180
IPv4Layer.h
pcpp::IcmpDestinationHostProhibited
Definition: IcmpLayer.h:105
pcpp::icmp_echo_request::data
uint8_t * data
Definition: IcmpLayer.h:153
pcpp::IcmpLayer::computeCalculateFields
void computeCalculateFields()
pcpp::IcmpLayer::isMessageOfType
bool isMessageOfType(IcmpMessageType type) const
pcpp::IcmpProtocolUnreachable
Definition: IcmpLayer.h:89
pcpp::IcmpLayer::getInfoRequestData
icmp_info_request * getInfoRequestData()