try
{
//Create the header
LPICMPHeader lpHead;
lpHead=ConstructICMP();
if (!lpHead)
{
ReportError("SendEcho","Failed to construct ICMP header!");
return FALSE;
}
//Protect it
std::auto_ptr<ICMPHeader> pProtection(lpHead);
//Check if echo or reply
if (bReply)
lpHead->ucICMPType=ICMP_Echo_Reply;
else
lpHead->ucICMPType=ICMP_Echo;
lpHead->ucICMPCode=0;
lpHead->sICMP.sUS.us1=htons(usIdentifier);
lpHead->sICMP.sUS.us2=htons(usSequence);
lpHead->ulICMP_Originate_Timestamp=htonl(ulData);
//And the checksum
lpHead->usICMPChecksum=CalculateChecksum((unsigned short*)lpHead,ICMPHeaderLength);
//Create the packet
return CreateFinal(lpHead,
usTotalSize);
}
ERROR_HANDLER_RETURN("GetEcho",NULL)