Examples/IcmpFileTransfer/IcmpFileTransfer-pitcher.cpp
/**
 * A callback used in the receiveFile() method and responsible to wait for the catcher to send an ICMP response containing the file name
 * to be received
 */
A callback used in the receiveFile() method and responsible to wait for the catcher to send an ICMP response containing the file name
to be received
A callback used in the receiveFile () method and responsible to wait for the catcher to send an ICMP response containing the file name to be received
static void waitForFileTransferStart(pcpp::RawPacket* rawPacket, pcpp::PcapLiveDevice* dev, void* icmpVoidData)
{
	pcpp::Packet parsedPacket(rawPacket);
	if (!parsedPacket.isPacketOfType(pcpp::ICMP) || !parsedPacket.isPacketOfType(pcpp::IPv4))
		return;
	if (icmpVoidData == NULL)
		return;
	IcmpFileTransferStartRecv* icmpFTStart = (IcmpFileTransferStartRecv*)icmpVoidData;
	pcpp::IcmpLayer* icmpLayer = parsedPacket.getLayerOfType<pcpp::IcmpLayer>();
	if (icmpLayer->getEchoReplyData() == NULL)
		return;
	pcpp::IPv4Layer* ip4Layer = parsedPacket.getLayerOfType<pcpp::IPv4Layer>();
	if (ip4Layer->getSrcIPv4Address() != icmpFTStart->catcherIPAddr || ip4Layer->getDstIPv4Address() != icmpFTStart->pitcherIPAddr)
		return;
	uint64_t resMsg = icmpLayer->getEchoReplyData()->header->timestamp;
	if (resMsg != ICMP_FT_START)
		return;
	if (icmpLayer->getEchoReplyData()->data == NULL)
		return;
	icmpFTStart->fileName = std::string((char*)icmpLayer->getEchoReplyData()->data);
	icmpFTStart->gotFileTransferStartMsg = true;
}
static void waitForFileTransferStart ( pcpp :: RawPacket * rawPacket , pcpp :: PcapLiveDevice * dev , void * icmpVoidData ) { pcpp :: Packet parsedPacket ( rawPacket ) ; if ( ! parsedPacket . isPacketOfType ( pcpp :: ICMP ) || ! parsedPacket . isPacketOfType ( pcpp :: IPv4 ) ) return ; if ( icmpVoidData == NULL ) return ; IcmpFileTransferStartRecv * icmpFTStart = ( IcmpFileTransferStartRecv * ) icmpVoidData ; pcpp :: IcmpLayer * icmpLayer = parsedPacket . getLayerOfType < pcpp :: IcmpLayer > ( ) ; if ( icmpLayer -> getEchoReplyData ( ) == NULL ) return ; pcpp :: IPv4Layer * ip4Layer = parsedPacket . getLayerOfType < pcpp :: IPv4Layer > ( ) ; if ( ip4Layer -> getSrcIPv4Address ( ) != icmpFTStart -> catcherIPAddr || ip4Layer -> getDstIPv4Address ( ) != icmpFTStart -> pitcherIPAddr ) return ; uint64_t resMsg = icmpLayer -> getEchoReplyData ( ) -> header -> timestamp ; if ( resMsg != ICMP_FT_START ) return ; if ( icmpLayer -> getEchoReplyData ( ) -> data == NULL ) return ; icmpFTStart -> fileName = std :: string ( ( char * ) icmpLayer -> getEchoReplyData ( ) -> data ) ; icmpFTStart -> gotFileTransferStartMsg = true ; }
A callback used in the receiveFile() method and responsible to wait for the catcher to send an ICMP response containing the file name
 to be received
A callback used in the receiveFile () method and responsible to wait for the catcher to send an ICMP response containing the file name to be received
// first, parse the packet
 // verify it's ICMP and IPv4 (IPv6 and ICMPv6 are not supported)
 // extract the ICMP layer, verify it's an ICMP reply
 // verify the source IP is the catcher's IP and the dest IP is the pitcher's IP
 // extract the message type in the ICMP reply timestamp field and check if it's  ICMP_FT_START
 // verify there is data in the ICMP reply
 // extract the file name from the ICMP reply data
 // signal the receiveFile() file name was extracted and it can stop capturing packets
