#pragma once #include #define ICMP_ECHO 8 #define ICMP_ECHOREPLY 0 #define ICMP_MIN 8 // minimum 8 byte icmp packet (just header) /* The IP header */ typedef struct iphdr { unsigned int h_len:4; // length of the header unsigned int version:4; // Version of IP unsigned char tos; // Type of service unsigned short total_len; // total length of the packet unsigned short ident; // unique identifier unsigned short frag_and_flags; // flags unsigned char ttl; unsigned char proto; // protocol (TCP, UDP etc) unsigned short checksum; // IP checksum unsigned int sourceIP; unsigned int destIP; }IpHeader; // // ICMP header // typedef struct icmphdr { BYTE i_type; BYTE i_code; /* type sub code */ USHORT i_cksum; USHORT i_id; USHORT i_seq; /* This is not the std header, but we reserve space for time */ ULONG timestamp; }IcmpHeader; using namespace std; // 在这里声明 typedef struct __ROUTERALARMSTRUCT { CString strIP; int nAlarmType; int nConfirm; }ROUTERALARMSTRUCT, *PROUTERALARMSTRUCT; #define STATUS_FAILED 0xFFFF #define DEF_PACKET_SIZE 32 #define DEF_PACKET_NUMBER 4 /* 发送数据报的个数 */ #define MAX_PACKET 1024 #define xmalloc(s) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(s)) #define xfree(p) HeapFree (GetProcessHeap(),0,(p)) extern ROUTERALARMSTRUCT g_tagRouterAlarm; extern vector<__ROUTERALARMSTRUCT > RouterAlarmArray; extern void fill_icmp_data(char *, int); extern USHORT checksum(USHORT *, int); extern int decode_resp(char *,int ,struct sockaddr_in *); extern int Ping(UINT nRetries, LPCSTR pstrHost); extern int InitPing(void); extern void UnInitPing(void);