| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #ifndef NETWORK_ICMPCLIENTIMPL_H
- #define NETWORK_ICMPCLIENTIMPL_H
- #include "Ipv4Header.h"
- #include "IcmpHeader.h"
- #include "asio.hpp"
- #include <condition_variable>
- #include <functional>
- #include <mutex>
- #include <string>
- #include <thread>
- #include <vector>
- namespace Network {
- class IcmpClientImpl
- {
- public:
- IcmpClientImpl();
- ~IcmpClientImpl();
- public:
- bool Ping(const std::string& targetAddress);
- private:
- void SendEchoRequest(const asio::ip::icmp::endpoint& targetEndpoint, const std::string& data);
- void StartReceive();
- void HandleReceive(const asio::error_code& error, std::size_t length);
- unsigned short GetIdentifier();
- private:
- std::thread m_thread;
- std::mutex m_mutex;
- std::condition_variable m_condition;
- asio::io_context m_ioContext;
- asio::ip::icmp::socket m_socket;
- asio::streambuf m_replyBuffer;
- bool m_done;
- };
- } // namespace Network
- #endif // NETWORK_ICMPCLIENTIMPL_H
|