47 lines
907 B
C++
47 lines
907 B
C++
#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
|