📄 icmp.h
字号:
// //
// Sets rcvSockAddr fields appropriately. //
// //
// Sets icmpSocketError and icmpSocketErrorMod to indicate the type //
// of error, and returns the integer result of the operation. //
// //
// icmpSocketError and icmpSocketErrorMod are preserved until the next //
// operation on this Icmp object is performed. //
// //
// DisplayError //
// Displays the provided ErrorType message prior to the decoded error //
// message in icmpSocketError and icmpSocketErrorMod. //
// //
// Sets the message box title to FunctionName. //
// //
// The message is displayed in a modal box, requiring an OK response //
// before the thread containing this method can progress. //
// //
//////////////////////////////////////////////////////////////////////////////////
// //
// Useage: //
// To use this class, copy the files Icmp.cpp, Icmp.h and Icmp.rc //
// to the same directory as your project. Include Icmp.cpp and //
// Icmp.rc in your project. This will cause an error notification //
// that only one .rc file can be active...ignore it, the next step //
// will fix it. Open the file Icmp.rc, select the string table, and //
// highlight all of the messages. Copy the resource strings to the //
// clipboard (copy button). Open the projects' string table and paste //
// the strings into the next available slot (paste button). Close //
// both string tables and remove (delete) the file Icmp.rc from your //
// project. //
// //
//////////////////////////////////////////////////////////////////////////////////
#pragma pack (4)
//////////////////////////////////////////////////////////////////
// //
// //
//////////////////////////////////////////////////////////////////
#define MAXBFRSIZE 2048
#define MAX_HOPS 30
typedef SOCKET * LPSOCKET;
typedef in_addr * LPINADDR;
//////////////////////////////////////////////////////////////////
// //
// IP Header //
// Implementation of RFC791 IP Header //
// //
//////////////////////////////////////////////////////////////////
typedef struct _IpHeader
{
unsigned int HeaderLength:4; // IP首部长度
unsigned int Version:4; // IP的版本
unsigned char TypeOfService; // 服务类型
unsigned short TotalLength; // 总的数据包大小
unsigned short Identification; // 特殊标识符
unsigned short FragmentationFlags; // 标志
unsigned char TTL; // Time To Live
unsigned char Protocol; // 协议 (TCP, UDP等)
unsigned short CheckSum; // 检验和
unsigned int sourceIPAddress; // 源地址
unsigned int destIPAddress; // 目标地址
} IpHeader;
typedef IpHeader FAR * LPIpHeader;
#define IpHeaderLength sizeof(IpHeader)
//////////////////////////////////////////////////////////////////
// //
// ICMP header //
// Implementation of RFC792 ICMP Header //
// //
//////////////////////////////////////////////////////////////////
typedef struct _IcmpHeader
{
BYTE IcmpType; //ICMP报文类型
BYTE IcmpCode; //ICMP代码
USHORT IcmpChecksum; //检验和
USHORT IcmpId; //标识符
USHORT IcmpSeq; //序列号
ULONG IcmpTimestamp; // 时间戳,非标准字段
} IcmpHeader;
typedef IcmpHeader FAR * LPIcmpHeader;
#define IcmpHeaderLength sizeof(IcmpHeader)
//////////////////////////////////////////////////////////////////
#define MAX_PACKET 2000 + IcmpHeaderLength
#define ICMP_ECHO 8
#define ICMP_ECHOREPLY 0
#define ICMP_MIN 8 // minimum 8 byte icmp packet (just header)
/////////////////////////////////////////////////////////////////////////////
// CIcmp command target
class CIcmp : public CSocket
{
// Attributes
public:
BOOL OpenNewSocket(HWND hWnd, unsigned int NotificationMessage, long NotifyEvents);
BOOL OpenNewSocket(HWND hWnd, unsigned int NotificationMessage, long NotifyEvents, int AFamily, int AType, int AProtocol);
int CloseIcmpSocket(void);
BOOL Connect(int ReceiveTimeout, int SendTimeout);
BOOL Connect(LPINT ReceiveTimeout, LPINT SendTimeout, int AFamily, int AType, int AProtocol);
int SetTTL(int TTL);
int SetAsynchNotification(HWND hWnd, unsigned int Message, long Events);
int Receive(LPSTR pIcmpBuffer, int IcmpBufferSize);
unsigned long GetIPAddress (LPSTR iHostName);
int Ping (LPSTR pIcmpBuffer, int IcmpBufferSize);
unsigned short IcmpChecksum(unsigned short FAR *lpBuf, int Len);
void DisplayError(CString ErrorType, CString FunctionName);
// Operations
public:
CIcmp(void);
CIcmp(CIcmp ©);
~CIcmp(void);
// CIcmp(CIcmp NewIcmp);
// Overrides
public:
private:
public:
//
// I/O Buffer Pointers
//
LPIcmpHeader pIcmpHeader;
LPIpHeader pIpHeader;
SOCKET icmpSocket;
SOCKADDR_IN icmpSockAddr;
SOCKADDR_IN rcvSockAddr;
DWORD icmpRoundTripTime;
DWORD icmpPingSentAt;
DWORD icmpPingReceivedAt;
int icmpRcvLen;
int icmpHops;
int icmpMaxHops;
int icmpCurSeq;
int icmpCurId;
int icmpPingTimer;
int icmpSocketError;
int icmpSocketErrorMod;
unsigned long icmpHostAddress;
protected:
};
typedef CIcmp FAR * LPIcmp;
/////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -