3 $Date: 2008/05/10 11:59:53 $
16 #include <sys/types.h>
17 #include <sys/socket.h>
18 #include <netinet/ip_icmp.h>
21 #if defined (FREE_BSD) || defined(DARWIN)
22 #include <netinet/in.h>
23 #include <netinet/in_systm.h>
24 #include <netinet/ip.h>
25 #include <netinet/ip_icmp.h>
26 #include <netinet/ip_var.h>
27 #include <arpa/inet.h>
30 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
66 //-----------------------------------------------------------------------------
72 //-----------------------------------------------------------------------------
74 #define PING_DATA_LEN (64)
75 //-----------------------------------------------------------------------------
79 char msg[PING_DATA_LEN];
81 //-----------------------------------------------------------------------------
85 typedef std::multimap<uint32_t, time_t> PingIPs;
86 typedef PingIPs::size_type SizeType;
88 explicit STG_PINGER(time_t delay = 15);
93 void AddIP(uint32_t ip);
94 void DelIP(uint32_t ip);
95 SizeType GetPingIPNum() const { return m_pingIP.size(); }
97 int GetIPTime(uint32_t ip, time_t * t) const;
98 void SetDelayTime(time_t d) { m_delay = d; }
99 time_t GetDelayTime() const { return m_delay; }
100 const std::string & GetStrError() const { return m_errorStr; }
103 uint16_t PingCheckSum(void * data, int len);
104 int SendPing(uint32_t ip);
109 static void * RunSendPing(void * d);
110 static void * RunRecvPing(void * d);
114 bool m_isRunningRecver;
115 bool m_isRunningSender;
118 pthread_t m_sendThread;
119 pthread_t m_recvThread;
121 PING_MESSAGE m_pmSend;
124 std::string m_errorStr;
126 std::multimap<uint32_t, time_t> m_pingIP;
127 std::list<uint32_t> m_ipToAdd;
128 std::list<uint32_t> m_ipToDel;
130 mutable pthread_mutex_t m_mutex;