00001 // icmp.h 00002 00003 #include <windows.h> 00004 00005 #define ICMP_ECHO_REPLY 0 00006 #define ICMP_ECHO_REQUEST 8 00007 #define ICMP_DESTINATION_UNREACHABLE 3 00008 #define ICMP_TIME_EXCEEDED 11 00009 00010 #pragma pack(push, 1) 00011 // See RFC 791 00012 typedef struct tagIP_HEADER 00013 { 00014 unsigned char h_len:4; // length of the header 00015 unsigned char version:4; // Version of IP 00016 unsigned char tos; // Type of service 00017 unsigned short total_len; // total length of the packet 00018 unsigned short ident; // unique identifier 00019 unsigned short frag_and_flags; // flags 00020 unsigned char ttl; 00021 unsigned char proto; // protocol (TCP, UDP etc) 00022 unsigned short checksum; // IP checksum 00023 unsigned long sourceIP; 00024 unsigned long destIP; 00025 } IP_HEADER; 00026 00027 // RFC 792 00028 typedef struct tagICMP_HEADER 00029 { 00030 BYTE type; 00031 BYTE code; // type sub code 00032 USHORT cksum; 00033 USHORT id; 00034 USHORT seq; 00035 } ICMP_HEADER; 00036 #pragma pack(pop) 00037 00038 00039 void FillICMPData(char* pData, int size); 00040 USHORT IPChecksum(USHORT* pBuffer, int nSize); 00041 void EncodePacket(char* pPacket, int iDataSize, USHORT uSequence); 00042 bool DecodePacket(char* pPacket, int iSize, USHORT& uSequence, LONGLONG& llTick);
1.4.3