MyPingip.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #include <WinSock.h>
  3. //#include "Logger.h"
  4. #define REQ_DATASIZE 32 //Echo请求数据的大小
  5. class CMyPingip
  6. {
  7. public:
  8. CMyPingip(void);
  9. ~CMyPingip(void);
  10. public:
  11. HWND m_hWnd; //窗口句柄
  12. bool PingFunction(LPCSTR pstrHost/*, Logger *pLog*/);
  13. int WaitForEchoReply(SOCKET s);
  14. //ICMP回应的请求和回答函数
  15. int SendEchoRequest(SOCKET, LPSOCKADDR_IN);
  16. DWORD RecvEchoReply(SOCKET, LPSOCKADDR_IN,u_char *pTTL);
  17. u_short in_cksum(u_short *addr, int len);
  18. protected:
  19. };
  20. typedef struct IP_HDR
  21. {
  22. u_char VIHL; //Version and IHL
  23. u_char TOS; //Type Of Service
  24. short TotLen; //总长度
  25. short ID; //标识
  26. short FlagOff; //标记
  27. u_char TTL; //生命期
  28. u_char Protocol; //协议
  29. u_short Checksum; //检查和
  30. struct in_addr iaSrc; //源地址
  31. struct in_addr iaDst; //目的地址
  32. }IPHDR, *PIPHDR;
  33. typedef struct IC_MPHDR
  34. {
  35. u_char Type; //类型
  36. u_char Code; //编码
  37. u_short Checksum; //检查和
  38. u_short ID; //标识
  39. u_short Seq; //顺序
  40. char Data; //数据
  41. }ICMPHDR, *PICMPHDR;
  42. typedef struct ICMPECHOREQUEST
  43. {
  44. ICMPHDR icmpHdr;
  45. DWORD dwTime;
  46. char cData[REQ_DATASIZE];
  47. }ECHOREQUEST, *PECHOREQUEST;
  48. typedef struct ICMPECHOREPLY
  49. {
  50. IPHDR iphdr;
  51. ECHOREQUEST echorequest;
  52. char cFiller[256];
  53. }ECHOREPLY, *PECHOREPLY;