📄 ping.h
字号:
// Ping.h: interface for the CPing class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_PING_H__632733B0_0996_4C34_9ABF_6A688ABE1EA1__INCLUDED_)
#define AFX_PING_H__632733B0_0996_4C34_9ABF_6A688ABE1EA1__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <winsock.h>
#include <stdarg.h>
#define ICMP_ECHOREPLY 0
#define ICMP_ECHOREQ 8
#define PING_SUCCESS 1
#define PING_WORKING 0
#define PING_SOCKET_ERROR -1
#define PING_HOST_NOTFOUND -2
#define PING_INIT_ERROR -3
#define VERSION_NOT_SUPPORT -4
#define PING_CONNECTION_ERROR -5
#define PING_TIMEOUT_ERROR -6
class CPing
{
public:
void SetInterval( int IInterval);
CPing();
virtual ~CPing();
CString m_sHost;
int m_iError;
CString m_sError;
CString sMsg;
int m_iInterval;
// Internal Functions
int DoPing(LPCSTR pstrHost);
void ReportError(int iErrorNo, char *format, ...);
//int average( int first, ... );
int WaitForEchoReply(SOCKET s);
u_short in_cksum(u_short *addr, int len);
// ICMP Echo Request/Reply functions
int SendEchoRequest(SOCKET, LPSOCKADDR_IN);
DWORD RecvEchoReply(SOCKET, LPSOCKADDR_IN, u_char *);
protected:
void Init();
};
#pragma pack(1)
#define ICMP_ECHOREPLY 0
#define ICMP_ECHOREQ 8
// IP Header -- RFC 791
typedef struct tagIPHDR
{
u_char VIHL; // Version and IHL
u_char TOS; // Type Of Service
short TotLen; // Total Length
short ID; // Identification
short FlagOff; // Flags and Fragment Offset
u_char TTL; // Time To Live
u_char Protocol; // Protocol
u_short Checksum; // Checksum
struct in_addr iaSrc; // Internet Address - Source
struct in_addr iaDst; // Internet Address - Destination
}IPHDR, *PIPHDR;
// ICMP Header - RFC 792
typedef struct tagICMPHDR
{
u_char Type; // Type
u_char Code; // Code
u_short Checksum; // Checksum
u_short ID; // Identification
u_short Seq; // Sequence
char Data; // Data
}ICMPHDR, *PICMPHDR;
#define REQ_DATASIZE 32 // Echo Request Data size
// ICMP Echo Request
typedef struct tagECHOREQUEST
{
ICMPHDR icmpHdr;
DWORD dwTime;
char cData[REQ_DATASIZE];
}ECHOREQUEST, *PECHOREQUEST;
// ICMP Echo Reply
typedef struct tagECHOREPLY
{
IPHDR ipHdr;
ECHOREQUEST echoRequest;
char cFiller[256];
}ECHOREPLY, *PECHOREPLY;
#pragma pack()
#endif // !defined(AFX_PING_H__632733B0_0996_4C34_9ABF_6A688ABE1EA1__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -