ping.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include <vector>
  3. #define ICMP_ECHO 8
  4. #define ICMP_ECHOREPLY 0
  5. #define ICMP_MIN 8 // minimum 8 byte icmp packet (just header)
  6. /* The IP header */
  7. typedef struct iphdr {
  8. unsigned int h_len:4; // length of the header
  9. unsigned int version:4; // Version of IP
  10. unsigned char tos; // Type of service
  11. unsigned short total_len; // total length of the packet
  12. unsigned short ident; // unique identifier
  13. unsigned short frag_and_flags; // flags
  14. unsigned char ttl;
  15. unsigned char proto; // protocol (TCP, UDP etc)
  16. unsigned short checksum; // IP checksum
  17. unsigned int sourceIP;
  18. unsigned int destIP;
  19. }IpHeader;
  20. //
  21. // ICMP header
  22. //
  23. typedef struct icmphdr
  24. {
  25. BYTE i_type;
  26. BYTE i_code; /* type sub code */
  27. USHORT i_cksum;
  28. USHORT i_id;
  29. USHORT i_seq;
  30. /* This is not the std header, but we reserve space for time */
  31. ULONG timestamp;
  32. }IcmpHeader;
  33. using namespace std; // 在这里声明
  34. typedef struct __ROUTERALARMSTRUCT
  35. {
  36. CString strIP;
  37. int nAlarmType;
  38. int nConfirm;
  39. }ROUTERALARMSTRUCT, *PROUTERALARMSTRUCT;
  40. #define STATUS_FAILED 0xFFFF
  41. #define DEF_PACKET_SIZE 32
  42. #define DEF_PACKET_NUMBER 4 /* 发送数据报的个数 */
  43. #define MAX_PACKET 1024
  44. #define xmalloc(s) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(s))
  45. #define xfree(p) HeapFree (GetProcessHeap(),0,(p))
  46. extern ROUTERALARMSTRUCT g_tagRouterAlarm;
  47. extern vector<__ROUTERALARMSTRUCT > RouterAlarmArray;
  48. extern void fill_icmp_data(char *, int);
  49. extern USHORT checksum(USHORT *, int);
  50. extern int decode_resp(char *,int ,struct sockaddr_in *);
  51. extern int Ping(UINT nRetries, LPCSTR pstrHost);
  52. extern int InitPing(void);
  53. extern void UnInitPing(void);