3 $Date: 2008/05/10 11:59:53 $
12 #pragma GCC diagnostic push
13 #pragma GCC diagnostic ignored "-Wshadow"
14 #include <jthread.hpp>
15 #pragma GCC diagnostic pop
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <netinet/ip_icmp.h>
25 #if defined (FREE_BSD) || defined(DARWIN)
26 #include <netinet/in.h>
27 #include <netinet/in_systm.h>
28 #include <netinet/ip.h>
29 #include <netinet/ip_icmp.h>
30 #include <netinet/ip_var.h>
31 #include <arpa/inet.h>
34 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
76 //-----------------------------------------------------------------------------
78 #define PING_DATA_LEN (64)
79 //-----------------------------------------------------------------------------
83 char msg[PING_DATA_LEN];
85 //-----------------------------------------------------------------------------
89 using PingIPs = std::multimap<uint32_t, time_t>;
91 explicit STG_PINGER(unsigned delay = 15);
95 void AddIP(uint32_t ip);
96 void DelIP(uint32_t ip);
97 auto GetPingIPNum() const { std::lock_guard lock(m_mutex); return m_pingIPs.size(); }
99 bool GetIPTime(uint32_t ip, time_t& t) const;
100 void SetDelayTime(unsigned d) { m_delay = d; }
101 unsigned GetDelayTime() const { return m_delay; }
102 const std::string& GetStrError() const { return m_errorStr; }
105 uint16_t PingCheckSum(const void* data, int len);
106 bool SendPing(uint32_t ip);
109 void RunSendPing(std::stop_token token);
110 void RunRecvPing(std::stop_token token);
112 mutable std::mutex m_mutex;
115 bool m_isRunningRecver;
116 bool m_isRunningSender;
119 std::jthread m_sendThread;
120 std::jthread m_recvThread;
122 PING_MESSAGE m_pmSend;
125 std::string m_errorStr;