PingSocket.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:3k
源码类别:

模拟服务器

开发平台:

C/C++

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //  
  3. //  FileName    :   PingSocket.h
  4. //  Version     :   1.0
  5. //  Creater     :   Linsuyi
  6. //  Date        :   2002-01-10  09:21:42
  7. //  Comment     :   Tcp/ip ping socket header file
  8. //  
  9. ////////////////////////////////////////////////////////////////////////////////
  10. #if !defined(AFX_PINGSOCKET_H__752184FA_8742_4259_814E_25442FC6A7ED__INCLUDED_)
  11. #define AFX_PINGSOCKET_H__752184FA_8742_4259_814E_25442FC6A7ED__INCLUDED_
  12. #if _MSC_VER > 1000
  13. #pragma once
  14. #endif // _MSC_VER > 1000
  15. #include "RawSocket.h"
  16. #include "InetStruct.h"
  17. #define PINGEVENT_OCCUROVER                 0x0000
  18. #define PINGEVENT_OCCURSTART                0x0001
  19. #define PINGEVENT_OCCURERROR                0x0002
  20. #define PINGEVENT_HOSTNOTFOUND              0x0003
  21. #define PINGEVENT_REPEAT                    0x0004
  22. #define PINGEVENT_TIMEOUT                   0x0005
  23. #define PINGEVENT_TESTBREAK                 0x0006
  24. #define PINGEVENT_THREADEXIT                0x0007
  25. #define PINGEVENT_THREADIDLE                0x0008
  26. // Ping Echo Request
  27. typedef struct tagPING_ECHOREQ
  28. {
  29.     ICMPHDR icmpHdr;
  30.     
  31.     unsigned int  unSignMain;
  32.     unsigned int  unSignExt;
  33.     unsigned int  unTimeMain;
  34.     unsigned int  unTimeExt;
  35.     
  36.     unsigned char byData[ICMP_DATAMINSIZE];
  37.     
  38. } PING_ECHOREQUEST, *PPING_ECHOREQUEST;
  39. // Ping Echo Reply
  40. typedef struct tagPING_ECHOREP
  41. {
  42.     IPHDR   ipHdr;
  43.     PING_ECHOREQUEST echoRequest;
  44.     
  45.     unsigned char byFillField[128];
  46.     
  47. } PING_ECHOREPLY, *PPING_ECHOREPLY;
  48. #define DEFAULT_PING_ID                     'SK'
  49. #define DEFAULT_PING_SEQUENCE               0x0301
  50. #define DEFAULT_PING_SIGN_MAIN              '3PUK'
  51. #define DEFAULT_PING_SIGN_EXT               'KCSH'
  52. #define DEFAULT_PING_TIMEOUT                1000
  53. #define PINGRESULT_SUCCESS                  0
  54. #define PINGRESULT_TIMEOUT                  1
  55. #define PINGRESULT_TESTBREAK                2
  56. #define PINGRESULT_OCCURERROR               3
  57. class CPingSocket
  58.   : public CRawSocket
  59. {
  60. public:
  61.     CPingSocket();
  62.     virtual ~CPingSocket();
  63.     
  64. public:
  65.     virtual int Create();
  66.     
  67. public:
  68.     int PingToAddress(const char *pcszRemoteAddr, int& nTimeOut);
  69.     int PingToAddress(const INET_ADDRESS *pszRemoteAddr, int& nTimeOut);
  70.     
  71.     int GetLastPingTime();
  72.     
  73. protected:
  74.     virtual int OnPingDataSend(int *pnBufSize, unsigned char **ppbyDataSend);
  75.     virtual int OnPingDataReceive(int *pnBufSize, unsigned char **pbyDataReceive);
  76.     
  77.     virtual int OnPingStatus(int nOccurEvent);
  78.     
  79. protected:
  80.     int DoEventNotify(int nOccurEvent);
  81.     
  82. protected:
  83.     int m_nLastSequence;
  84.     int m_nLastPingTime;
  85.     
  86. private:
  87.     virtual void OnErrorHandler();
  88. };
  89. #endif // !defined(AFX_PINGSOCKET_H__752184FA_8742_4259_814E_25442FC6A7ED__INCLUDED_)