Examples/IcmpFileTransfer/IcmpFileTransfer-pitcher.cpp
/**
 * A callback used in the sendFile() method and responsible to wait for ICMP responses coming from the catcher indicating it's alive
 * and ready for file transfer to start
 */
A callback used in the sendFile() method and responsible to wait for ICMP responses coming from the catcher indicating it's alive
and ready for file transfer to start
A callback used in the sendFile () method and responsible to wait for ICMP responses coming from the catcher indicating it ' s alive and ready for file transfer to start
static bool waitForFileTransferStartAck(pcpp::RawPacket* rawPacket, pcpp::PcapLiveDevice* dev, void* icmpVoidData)
{
	pcpp::Packet parsedPacket(rawPacket);
	if (!parsedPacket.isPacketOfType(pcpp::ICMP) || !parsedPacket.isPacketOfType(pcpp::IPv4))
		return false;
	if (icmpVoidData == NULL)
		return false;
	IcmpFileTransferStartSend* icmpData = (IcmpFileTransferStartSend*)icmpVoidData;
	pcpp::IcmpLayer* icmpLayer = parsedPacket.getLayerOfType<pcpp::IcmpLayer>();
	if (icmpLayer->getEchoReplyData() == NULL)
		return false;
	if (icmpLayer->getEchoReplyData()->header->id != pcpp::hostToNet16(icmpData->icmpMsgId))
		return false;
	pcpp::IPv4Layer* ip4Layer = parsedPacket.getLayerOfType<pcpp::IPv4Layer>();
	if (ip4Layer->getSrcIPv4Address() != icmpData->catcherIPAddr || ip4Layer->getDstIPv4Address() != icmpData->pitcherIPAddr)
		return false;
	uint64_t resMsg = icmpLayer->getEchoReplyData()->header->timestamp;
	if (resMsg != ICMP_FT_ACK)
		return false;
	return true;
}
static bool waitForFileTransferStartAck ( pcpp :: RawPacket * rawPacket , pcpp :: PcapLiveDevice * dev , void * icmpVoidData ) { pcpp :: Packet parsedPacket ( rawPacket ) ; if ( ! parsedPacket . isPacketOfType ( pcpp :: ICMP ) || ! parsedPacket . isPacketOfType ( pcpp :: IPv4 ) ) return false ; if ( icmpVoidData == NULL ) return false ; IcmpFileTransferStartSend * icmpData = ( IcmpFileTransferStartSend * ) icmpVoidData ; pcpp :: IcmpLayer * icmpLayer = parsedPacket . getLayerOfType < pcpp :: IcmpLayer > ( ) ; if ( icmpLayer -> getEchoReplyData ( ) == NULL ) return false ; if ( icmpLayer -> getEchoReplyData ( ) -> header -> id != pcpp :: hostToNet16 ( icmpData -> icmpMsgId ) ) return false ; pcpp :: IPv4Layer * ip4Layer = parsedPacket . getLayerOfType < pcpp :: IPv4Layer > ( ) ; if ( ip4Layer -> getSrcIPv4Address ( ) != icmpData -> catcherIPAddr || ip4Layer -> getDstIPv4Address ( ) != icmpData -> pitcherIPAddr ) return false ; uint64_t resMsg = icmpLayer -> getEchoReplyData ( ) -> header -> timestamp ; if ( resMsg != ICMP_FT_ACK ) return false ; return true ; }
A callback used in the sendFile() method and responsible to wait for ICMP responses coming from the catcher indicating it's alive
 and ready for file transfer to start
A callback used in the sendFile () method and responsible to wait for ICMP responses coming from the catcher indicating it ' s alive and ready for file transfer to start
// 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 ICMP ID of the reply matched the ICMP ID the pitcher sent in the request
 // verify the source IP is the catcher's IP and the dest IP is the pitcher's IP
 // verify the message type is ICMP_FT_ACK
 // if arrived to here it means we got a response from the catcher and it's ready for file transfer to start
