#pragma once #include //#include "Logger.h" #define REQ_DATASIZE 32 //Echo请求数据的大小 class CMyPingip { public: CMyPingip(void); ~CMyPingip(void); public: HWND m_hWnd; //窗口句柄 bool PingFunction(LPCSTR pstrHost/*, Logger *pLog*/); int WaitForEchoReply(SOCKET s); //ICMP回应的请求和回答函数 int SendEchoRequest(SOCKET, LPSOCKADDR_IN); DWORD RecvEchoReply(SOCKET, LPSOCKADDR_IN,u_char *pTTL); u_short in_cksum(u_short *addr, int len); protected: }; typedef struct IP_HDR { u_char VIHL; //Version and IHL u_char TOS; //Type Of Service short TotLen; //总长度 short ID; //标识 short FlagOff; //标记 u_char TTL; //生命期 u_char Protocol; //协议 u_short Checksum; //检查和 struct in_addr iaSrc; //源地址 struct in_addr iaDst; //目的地址 }IPHDR, *PIPHDR; typedef struct IC_MPHDR { u_char Type; //类型 u_char Code; //编码 u_short Checksum; //检查和 u_short ID; //标识 u_short Seq; //顺序 char Data; //数据 }ICMPHDR, *PICMPHDR; typedef struct ICMPECHOREQUEST { ICMPHDR icmpHdr; DWORD dwTime; char cData[REQ_DATASIZE]; }ECHOREQUEST, *PECHOREQUEST; typedef struct ICMPECHOREPLY { IPHDR iphdr; ECHOREQUEST echorequest; char cFiller[256]; }ECHOREPLY, *PECHOREPLY;