#pragmapack(4)
#defineWIN32_LEAN_AND_MEAN
#include
#include
#include
#defineICMP_ECHO8
#defineICMP_ECHOREPLY0
#defineICMP_MIN8//minimum8byteicmppacket(justheader)
/*TheIPheader*/
typedefstrUCtiphdr{
unsignedinth_len:4;//lengthoftheheader
unsignedintversion:4;//VersionofIP
unsignedchartos;//Typeofservice
unsignedshorttotal_len;//totallengthofthepacket
unsignedshortident;//uniqueidentifier
unsignedshortfrag_and_flags;//flags
unsignedcharttl;
unsignedcharproto;//protocol(TCP,UDPetc)
unsignedshortchecksum;//IPchecksum
unsignedintsourceIP;
unsignedintdestIP;
}IpHeader;
//
//ICMPheader
//
typedefstruct_ihdr{
BYTEi_type;
BYTEi_code;/*typesubcode*/
USHORTi_cksum;
USHORTi_id;
USHORTi_seq;
/*Thisisnotthestdheader,butwereservespacefortime*/
ULONGtimestamp;
}IcmpHeader;
#defineSTATUS_FAILED0xFFFF
#defineDEF_PACKET_SIZE32
#defineMAX_PACKET1024
#definexmalloc(s)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(s))
#definexfree(p)HeapFree(GetProcessHeap(),0,(p))
voidfill_icmp_data(char*,int);
USHORTchecksum(USHORT*,int);
voiddecode_resp(char*,int,structsockaddr_in*);
voidUsage(char*progname){
fprintf(stderr,"Usage:\n";
fprintf(stderr,"%s[data_size]\n",progname);
fprintf(stderr,"datasizecanbeupto1Kb\n";
ExitProcess(STATUS_FAILED);
}
intmain(intargc,char**argv){
WSADATAwsaData;
SOCKETsockRaw;
structsockaddr_indest,from;
structhostent*hp;
intbread,datasize;
intfromlen=sizeof(from);
inttimeout=1000;
char*dest_ip;
char*icmp_data;
char*recvbuf;
unsignedintaddr=0;
USHORTseq_no=0;
if(WSAStartup(MAKEWord(2,1),