⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hicmp.h

📁 枚举主机网络设备
💻 H
字号:
// CHIcmp.h: interface for the CHIcmp class.
#ifndef __HICMP_H__
#define __HICMP_H__
#include <HLib32.h>

#define ICMP_ECHO			8
#define ICMP_ECHOREPLY		0
#define STATUS_FAILED		0xFFFF
#define DEF_PACKET_SIZE		32
#define MAX_PACKET			1024
#define ICMP_MIN			8			// minimum 8 byte icmp packet (just header)

#define ICMP_NO_ERROR		0			// icmp state

#define xmalloc(s) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(s))
#define xfree(p)   HeapFree (GetProcessHeap(),0,(p))

/* The IP header */
typedef struct iphdr {
	unsigned int h_len:4;          // length of the header
	unsigned int version:4;        // Version of IP
	unsigned char tos;             // Type of service
	unsigned short total_len;      // total length of the packet
	unsigned short ident;          // unique identifier
	unsigned short frag_and_flags; // flags
	unsigned char  ttl; 
	unsigned char proto;           // protocol (TCP, UDP etc)
	unsigned short checksum;       // IP checksum

	unsigned int sourceIP;
	unsigned int destIP;

}IpHeader;

//
// ICMP header
//
typedef struct _ihdr {
  BYTE i_type;
  BYTE i_code; /* type sub code */
  USHORT i_cksum;
  USHORT i_id;
  USHORT i_seq;
  USHORT i_thread_seq;
  /* This is not the std header, but we reserve space for time */
  ULONG timestamp;
}IcmpHeader;

typedef struct _state
{
	BYTE		State;				//State = 0, no error
	char		szState[MAX_PATH];	//Give human readable string to locate error
	int			Time;				//Icmp reply time
} State;

class CHIcmp
{
public:
	int GetState();
	BOOL Init();
	CHIcmp(int nTimeOutms=500);
	virtual ~CHIcmp();
	int Ping(DWORD dwIP);
	int Ping(char *szIP);
	void Close();
protected:
	void SetError(BYTE i, char *str, int time=-1);
	void GetIPAddr(char *szDestAddr);

	void fill_icmp_data(char* icmp_data, int size);
	USHORT checksum(USHORT* buffer, int size);
	void decode_resp(char* recvbuf, int bread);
protected:
	WSADATA					m_wsaData;
	SOCKET					m_sockRaw;
	struct sockaddr_in		m_dest, m_from;
	struct hostent*			m_hp;
	State					m_icmpState;
	char*					m_dest_ip;
	int						m_timeout;
	int						m_datasize;
	USHORT					m_seq_no;
};

#endif //__HICMP_H__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -