PcapPlusPlus
pcpp::IcmpLayer Class Reference

#include <IcmpLayer.h>

Inheritance diagram for pcpp::IcmpLayer:
pcpp::Layer pcpp::IDataContainer

Public Member Functions

 IcmpLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
 IcmpLayer ()
 
icmphdrgetIcmpHeader ()
 
IcmpMessageType getMessageType ()
 
bool isMessageOfType (IcmpMessageType type)
 
icmp_echo_requestgetEchoRequestData ()
 
icmp_echo_requestsetEchoRequestData (uint16_t id, uint16_t sequence, uint64_t timestamp, const uint8_t *data, size_t dataLen)
 
icmp_echo_replygetEchoReplyData ()
 
icmp_echo_replysetEchoReplyData (uint16_t id, uint16_t sequence, uint64_t timestamp, const uint8_t *data, size_t dataLen)
 
icmp_timestamp_requestgetTimestampRequestData ()
 
icmp_timestamp_requestsetTimestampRequestData (uint16_t id, uint16_t sequence, timeval originateTimestamp)
 
icmp_timestamp_replygetTimestampReplyData ()
 
icmp_timestamp_replysetTimestampReplyData (uint16_t id, uint16_t sequence, timeval originateTimestamp, timeval receiveTimestamp, timeval transmitTimestamp)
 
icmp_destination_unreachablegetDestUnreachableData ()
 
icmp_destination_unreachablesetDestUnreachableData (IcmpDestUnreachableCodes code, uint16_t nextHopMTU, IPv4Layer *ipHeader, Layer *l4Header)
 
icmp_source_quenchgetSourceQuenchdata ()
 
icmp_source_quenchsetSourceQuenchdata (IPv4Layer *ipHeader, Layer *l4Header)
 
icmp_redirectgetRedirectData ()
 
icmp_redirectsetRedirectData (uint8_t code, IPv4Address gatewayAddress, IPv4Layer *ipHeader, Layer *l4Header)
 
icmp_router_advertisementgetRouterAdvertisementData ()
 
icmp_router_advertisementsetRouterAdvertisementData (uint8_t code, uint16_t lifetimeInSeconds, const std::vector< icmp_router_address_structure > &routerAddresses)
 
icmp_router_solicitationgetRouterSolicitationData ()
 
icmp_router_solicitationsetRouterSolicitationData ()
 
icmp_time_exceededgetTimeExceededData ()
 
icmp_time_exceededsetTimeExceededData (uint8_t code, IPv4Layer *ipHeader, Layer *l4Header)
 
icmp_param_problemgetParamProblemData ()
 
icmp_param_problemsetParamProblemData (uint8_t code, uint8_t errorOctetPointer, IPv4Layer *ipHeader, Layer *l4Header)
 
icmp_address_mask_requestgetAddressMaskRequestData ()
 
icmp_address_mask_requestsetAddressMaskRequestData (uint16_t id, uint16_t sequence, IPv4Address mask)
 
icmp_address_mask_replygetAddressMaskReplyData ()
 
icmp_address_mask_replysetAddressMaskReplyData (uint16_t id, uint16_t sequence, IPv4Address mask)
 
icmp_info_requestgetInfoRequestData ()
 
icmp_info_requestsetInfoRequestData (uint16_t id, uint16_t sequence)
 
icmp_info_replygetInfoReplyData ()
 
icmp_info_replysetInfoReplyData (uint16_t id, uint16_t sequence)
 
void parseNextLayer ()
 
size_t getHeaderLen ()
 
void computeCalculateFields ()
 
std::string toString ()
 
OsiModelLayer getOsiModelLayer ()
 
- Public Member Functions inherited from pcpp::Layer
virtual ~Layer ()
 
LayergetNextLayer ()
 
LayergetPrevLayer ()
 
ProtocolType getProtocol ()
 
uint8_t * getData ()
 
size_t getDataLen ()
 
uint8_t * getLayerPayload ()
 
size_t getLayerPayloadSize ()
 
bool isAllocatedToPacket ()
 
void copyData (uint8_t *toArr)
 
uint8_t * getDataPtr (size_t offset=0)
 

Detailed Description

Represents an ICMP protocol layer (for IPv4 only)

Constructor & Destructor Documentation

◆ IcmpLayer() [1/2]

pcpp::IcmpLayer::IcmpLayer ( uint8_t *  data,
size_t  dataLen,
Layer prevLayer,
Packet packet 
)
inline

A constructor that creates the layer from an existing packet raw data

Parameters
[in]dataA pointer to the raw data (will be casted to arphdr)
[in]dataLenSize of the data in bytes
[in]prevLayerA pointer to the previous layer
[in]packetA pointer to the Packet instance where layer will be stored in

◆ IcmpLayer() [2/2]

pcpp::IcmpLayer::IcmpLayer ( )

An empty constructor that creates a new layer with an empty ICMP header without setting the ICMP type or ICMP data. Call the set*Data() methods to set ICMP type and data

Member Function Documentation

◆ computeCalculateFields()

void pcpp::IcmpLayer::computeCalculateFields ( )
virtual

Calculate ICMP checksum field

Implements pcpp::Layer.

◆ getAddressMaskReplyData()

icmp_address_mask_reply* pcpp::IcmpLayer::getAddressMaskReplyData ( )
Returns
ICMP address mask reply data. If the layer isn't of type ICMP address mask reply NULL is returned

◆ getAddressMaskRequestData()

icmp_address_mask_request* pcpp::IcmpLayer::getAddressMaskRequestData ( )
Returns
ICMP address mask request data. If the layer isn't of type ICMP address mask request NULL is returned

◆ getDestUnreachableData()

icmp_destination_unreachable* pcpp::IcmpLayer::getDestUnreachableData ( )
Returns
ICMP destination unreachable data. If the layer isn't of type ICMP destination unreachable NULL is returned. The IP and L4 (ICMP/TCP/UDP) headers of the destination unreachable data are parsed as separate layers and can be retrieved via this->getNextLayer()

◆ getEchoReplyData()

icmp_echo_reply* pcpp::IcmpLayer::getEchoReplyData ( )
Returns
ICMP echo reply data. If the layer isn't of type ICMP echo reply NULL is returned

◆ getEchoRequestData()

icmp_echo_request* pcpp::IcmpLayer::getEchoRequestData ( )
Returns
ICMP echo (ping) request data. If the layer isn't of type ICMP echo request NULL is returned

◆ getHeaderLen()

size_t pcpp::IcmpLayer::getHeaderLen ( )
virtual
Returns
The ICMP header length. This length varies according to the ICMP message type. This length doesn't include IPv4 and L4 headers in case ICMP message type are: ICMP_DEST_UNREACHABLE, ICMP_SOURCE_QUENCH, ICMP_TIME_EXCEEDED, ICMP_REDIRECT, ICMP_PARAM_PROBLEM

Implements pcpp::Layer.

◆ getIcmpHeader()

icmphdr* pcpp::IcmpLayer::getIcmpHeader ( )
inline

Get a pointer to the basic ICMP header. Notice this points directly to the data, so every change will change the actual packet data

Returns
A pointer to the icmphdr

◆ getInfoReplyData()

icmp_info_reply* pcpp::IcmpLayer::getInfoReplyData ( )
Returns
ICMP address information reply data. If the layer isn't of type ICMP information reply NULL is returned

◆ getInfoRequestData()

icmp_info_request* pcpp::IcmpLayer::getInfoRequestData ( )
Returns
ICMP address information request data. If the layer isn't of type ICMP information request NULL is returned

◆ getMessageType()

IcmpMessageType pcpp::IcmpLayer::getMessageType ( )
Returns
The ICMP message type

◆ getOsiModelLayer()

OsiModelLayer pcpp::IcmpLayer::getOsiModelLayer ( )
inlinevirtual
Returns
The OSI Model layer this protocol belongs to

Implements pcpp::Layer.

◆ getParamProblemData()

icmp_param_problem* pcpp::IcmpLayer::getParamProblemData ( )
Returns
ICMP parameter problem data. If the layer isn't of type ICMP parameter problem NULL is returned

◆ getRedirectData()

icmp_redirect* pcpp::IcmpLayer::getRedirectData ( )
Returns
ICMP redirect data. If the layer isn't of type ICMP redirect NULL is returned. The IP and L4 (ICMP/TCP/UDP) headers of the redirect data are parsed as separate layers and can be retrieved via this->getNextLayer()

◆ getRouterAdvertisementData()

icmp_router_advertisement* pcpp::IcmpLayer::getRouterAdvertisementData ( )
Returns
ICMP router advertisement data. If the layer isn't of type ICMP router advertisement NULL is returned

◆ getRouterSolicitationData()

icmp_router_solicitation* pcpp::IcmpLayer::getRouterSolicitationData ( )
Returns
ICMP router solicitation data. If the layer isn't of type ICMP router solicitation NULL is returned

◆ getSourceQuenchdata()

icmp_source_quench* pcpp::IcmpLayer::getSourceQuenchdata ( )
Returns
ICMP source quench data. If the layer isn't of type ICMP source quench NULL is returned. The IP and L4 (ICMP/TCP/UDP) headers of the source quench data are parsed as separate layers and can be retrieved via this->getNextLayer()

◆ getTimeExceededData()

icmp_time_exceeded* pcpp::IcmpLayer::getTimeExceededData ( )
Returns
ICMP time-to-live exceeded data. If the layer isn't of type ICMP time-to-live exceeded NULL is returned. The IP and L4 (ICMP/TCP/UDP) headers of the time exceeded data are parsed as separate layers and can be retrieved via this->getNextLayer()

◆ getTimestampReplyData()

icmp_timestamp_reply* pcpp::IcmpLayer::getTimestampReplyData ( )
Returns
ICMP timestamp reply data. If the layer isn't of type ICMP timestamp reply NULL is returned

◆ getTimestampRequestData()

icmp_timestamp_request* pcpp::IcmpLayer::getTimestampRequestData ( )
Returns
ICMP timestamp request data. If the layer isn't of type ICMP timestamp request NULL is returned

◆ isMessageOfType()

bool pcpp::IcmpLayer::isMessageOfType ( IcmpMessageType  type)
Parameters
[in]typeType to check
Returns
True if the layer if of the given type, false otherwise

◆ parseNextLayer()

void pcpp::IcmpLayer::parseNextLayer ( )
virtual

ICMP messages of types: ICMP_DEST_UNREACHABLE, ICMP_SOURCE_QUENCH, ICMP_TIME_EXCEEDED, ICMP_REDIRECT, ICMP_PARAM_PROBLEM have data that contains IPv4 header and some L4 header (TCP/UDP/ICMP). This method parses these headers as separate layers on top of the ICMP layer

Implements pcpp::Layer.

◆ setAddressMaskReplyData()

icmp_address_mask_reply* pcpp::IcmpLayer::setAddressMaskReplyData ( uint16_t  id,
uint16_t  sequence,
IPv4Address  mask 
)

Set address mask reply message data

Parameters
[in]idAddress mask reply identifier
[in]sequenceAddress mask reply sequence
[in]maskThe subnet mask of the requesting host
Returns
A pointer to the address mask reply data that have been set or NULL if something went wrong (an appropriate error log is printed in such cases)

◆ setAddressMaskRequestData()

icmp_address_mask_request* pcpp::IcmpLayer::setAddressMaskRequestData ( uint16_t  id,
uint16_t  sequence,
IPv4Address  mask 
)

Set address mask request message data

Parameters
[in]idAddress mask request identifier
[in]sequenceAddress mask request sequence
[in]maskThe subnet mask of the requesting host
Returns
A pointer to the address mask request data that have been set or NULL if something went wrong (an appropriate error log is printed in such cases)

◆ setDestUnreachableData()

icmp_destination_unreachable* pcpp::IcmpLayer::setDestUnreachableData ( IcmpDestUnreachableCodes  code,
uint16_t  nextHopMTU,
IPv4Layer ipHeader,
Layer l4Header 
)

Set destination unreachable message data. This method only works if IcmpLayer is already part of a packet (not a standalone layer). The reason is the Internet and L4 headers given as parameters are added as separate layers and need a packet to be added to

Parameters
[in]codeDestination unreachable code
[in]nextHopMTUThe MTU of the next-hop network if a code 4 error occurs
[in]ipHeaderThe Internet header of the original data. This layer is added as a separate layer on the packet
[in]l4HeaderThe L4 header of the original data. This layer is added as a separate layer on the packet
Returns
A pointer to the destination unreachable data that have been set or NULL if something went wrong (an appropriate error log is printed in such cases)

◆ setEchoReplyData()

icmp_echo_reply* pcpp::IcmpLayer::setEchoReplyData ( uint16_t  id,
uint16_t  sequence,
uint64_t  timestamp,
const uint8_t *  data,
size_t  dataLen 
)

Set echo (ping) reply message data

Parameters
[in]idEcho (ping) reply identifier
[in]sequenceEcho (ping) reply sequence
[in]timestampEcho (ping) reply timestamp
[in]dataA pointer to echo (ping) reply payload to set
[in]dataLenThe length of the echo (ping) reply payload
Returns
A pointer to the echo (ping) reply data that have been set or NULL if something went wrong (an appropriate error log is printed in such cases)

◆ setEchoRequestData()

icmp_echo_request* pcpp::IcmpLayer::setEchoRequestData ( uint16_t  id,
uint16_t  sequence,
uint64_t  timestamp,
const uint8_t *  data,
size_t  dataLen 
)

Set echo (ping) request message data

Parameters
[in]idEcho (ping) request identifier
[in]sequenceEcho (ping) request sequence
[in]timestampEcho (ping) request timestamp
[in]dataA pointer to echo (ping) request payload to set
[in]dataLenThe length of the echo (ping) request payload
Returns
A pointer to the echo (ping) request data that have been set or NULL if something went wrong (an appropriate error log is printed in such cases)

◆ setInfoReplyData()

icmp_info_reply* pcpp::IcmpLayer::setInfoReplyData ( uint16_t  id,
uint16_t  sequence 
)

Set information reply message data

Parameters
[in]idInformation reply identifier
[in]sequenceInformation reply sequence
Returns
A pointer to the information reply data that have been set or NULL if something went wrong (an appropriate error log is printed in such cases)

◆ setInfoRequestData()

icmp_info_request* pcpp::IcmpLayer::setInfoRequestData ( uint16_t  id,
uint16_t  sequence 
)

Set information request message data

Parameters
[in]idInformation request identifier
[in]sequenceInformation request sequence
Returns
A pointer to the information request data that have been set or NULL if something went wrong (an appropriate error log is printed in such cases)

◆ setParamProblemData()

icmp_param_problem* pcpp::IcmpLayer::setParamProblemData ( uint8_t  code,
uint8_t  errorOctetPointer,
IPv4Layer ipHeader,
Layer l4Header 
)

Set parameter problem message data. This method only works if IcmpLayer is already part of a packet (not a standalone layer). The reason is the Internet and L4 headers given as parameters are added as separate layers and need a packet to be added to

Parameters
[in]codeParameter problem message code. Only code between 0 and 2 are legal, the rest will fail the method
[in]errorOctetPointerIn the case of an invalid IP header (Code 0), indicate the byte offset of the error in the header
[in]ipHeaderThe Internet header of the original data. This layer is added as a separate layer on the packet
[in]l4HeaderThe L4 header of the original data. This layer is added as a separate layer on the packet
Returns
A pointer to the parameter problem data that have been set or NULL if something went wrong (an appropriate error log is printed in such cases)

◆ setRedirectData()

icmp_redirect* pcpp::IcmpLayer::setRedirectData ( uint8_t  code,
IPv4Address  gatewayAddress,
IPv4Layer ipHeader,
Layer l4Header 
)

Set redirect message data. This method only works if IcmpLayer is already part of a packet (not a standalone layer). The reason is the Internet and L4 headers given as parameters are added as separate layers and need a packet to be added to

Parameters
[in]codeThe redirect message code. Only values between 0 and 3 are legal, the rest will cause the method to fail
[in]gatewayAddressAn IPv4 address of the gateway to which the redirection should be sent
[in]ipHeaderThe Internet header of the original data. This layer is added as a separate layer on the packet
[in]l4HeaderThe L4 header of the original data. This layer is added as a separate layer on the packet
Returns
A pointer to the redirect data that have been set or NULL if something went wrong (an appropriate error log is printed in such cases)

◆ setRouterAdvertisementData()

icmp_router_advertisement* pcpp::IcmpLayer::setRouterAdvertisementData ( uint8_t  code,
uint16_t  lifetimeInSeconds,
const std::vector< icmp_router_address_structure > &  routerAddresses 
)

Set router advertisement message data

Parameters
[in]codeThe router advertisement message code. Only codes 0 or 16 are legal, the rest will fail the method
[in]lifetimeInSecondsThe maximum number of seconds that the router addresses in this list may be considered valid
[in]routerAddressesA vector of router advertisements to set
Returns
A pointer to the router advertisement data that have been set or NULL if something went wrong (an appropriate error log is printed in such cases)

◆ setRouterSolicitationData()

icmp_router_solicitation* pcpp::IcmpLayer::setRouterSolicitationData ( )

Set router solicitation message data. This message accepts no parameters as there are no parameters to this type of message (code is always zero)

Returns
A pointer to the router solicitation data that have been set or NULL if something went wrong (an appropriate error log is printed in such cases)

◆ setSourceQuenchdata()

icmp_source_quench* pcpp::IcmpLayer::setSourceQuenchdata ( IPv4Layer ipHeader,
Layer l4Header 
)

Set source quench message data. This method only works if IcmpLayer is already part of a packet (not a standalone layer). The reason is the Internet and L4 headers given as parameters are added as separate layers and need a packet to be added to

Parameters
[in]ipHeaderThe Internet header of the original data. This layer is added as a separate layer on the packet
[in]l4HeaderThe L4 header of the original data. This layer is added as a separate layer on the packet
Returns
A pointer to the source quench data that have been set or NULL if something went wrong (an appropriate error log is printed in such cases)

◆ setTimeExceededData()

icmp_time_exceeded* pcpp::IcmpLayer::setTimeExceededData ( uint8_t  code,
IPv4Layer ipHeader,
Layer l4Header 
)

Set time-to-live exceeded message data. This method only works if IcmpLayer is already part of a packet (not a standalone layer). The reason is the Internet and L4 headers given as parameters are added as separate layers and need a packet to be added to

Parameters
[in]codeTime-to-live exceeded message code. Only codes 0 or 1 are legal, the rest will fail the method
[in]ipHeaderThe Internet header of the original data. This layer is added as a separate layer on the packet
[in]l4HeaderThe L4 header of the original data. This layer is added as a separate layer on the packet
Returns
A pointer to the time-to-live exceeded data that have been set or NULL if something went wrong (an appropriate error log is printed in such cases)

◆ setTimestampReplyData()

icmp_timestamp_reply* pcpp::IcmpLayer::setTimestampReplyData ( uint16_t  id,
uint16_t  sequence,
timeval  originateTimestamp,
timeval  receiveTimestamp,
timeval  transmitTimestamp 
)

Set timestamp reply message data

Parameters
[in]idTimestamp reply identifier
[in]sequenceTimestamp reply sequence
[in]originateTimestampTime (in milliseconds since midnight) the sender last touched the packet
[in]receiveTimestampThe time the echoer first touched it on receipt
[in]transmitTimestampThe time the echoer last touched the message on sending it
Returns
A pointer to the timestamp reply data that have been set or NULL if something went wrong (an appropriate error log is printed in such cases)

◆ setTimestampRequestData()

icmp_timestamp_request* pcpp::IcmpLayer::setTimestampRequestData ( uint16_t  id,
uint16_t  sequence,
timeval  originateTimestamp 
)

Set timestamp request message data

Parameters
[in]idTimestamp request identifier
[in]sequenceTimestamp request sequence
[in]originateTimestampTime (in milliseconds since midnight) the sender last touched the packet
Returns
A pointer to the timestamp request data that have been set or NULL if something went wrong (an appropriate error log is printed in such cases)

◆ toString()

std::string pcpp::IcmpLayer::toString ( )
virtual
Returns
A string representation of the layer most important data (should look like the layer description in Wireshark)

Implements pcpp::Layer.