69 lines
1.4 KiB
C++
69 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "ehs/Serializer.h"
|
|
#include "ehs/Types.h"
|
|
#include "ehs/io/socket/Socket.h"
|
|
|
|
namespace ehs
|
|
{
|
|
struct ICMP_Header
|
|
{
|
|
UInt_8 type;
|
|
UInt_8 code;
|
|
UInt_16 checksum;
|
|
};
|
|
|
|
struct ICMP_EchoRequest
|
|
{
|
|
UInt_16 id;
|
|
UInt_16 sequence;
|
|
};
|
|
|
|
class BaseICMP
|
|
{
|
|
private:
|
|
IP version;
|
|
|
|
public:
|
|
virtual ~BaseICMP() = default;
|
|
|
|
BaseICMP();
|
|
|
|
BaseICMP(IP version);
|
|
|
|
BaseICMP(BaseICMP &&icmp) noexcept;
|
|
|
|
BaseICMP(const BaseICMP &icmp);
|
|
|
|
BaseICMP &operator=(BaseICMP &&icmp) noexcept;
|
|
|
|
BaseICMP &operator=(const BaseICMP &icmp);
|
|
|
|
virtual void Release();
|
|
|
|
UInt_64 Send(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size);
|
|
|
|
UInt_64 Receive(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data);
|
|
|
|
void SendEchoRequest(const Str_8 &address, ICMP_EchoRequest er, const Byte *data, UInt_64 size);
|
|
|
|
virtual void SetReceiveTimeout(UInt_64 timeout);
|
|
|
|
IP GetVersion() const;
|
|
|
|
virtual bool IsValid() const;
|
|
|
|
protected:
|
|
static UInt_16 ComputeChecksumV4(UInt_16 *buffer, Size length);
|
|
|
|
private:
|
|
virtual UInt_64 SendV6(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size);
|
|
|
|
virtual UInt_64 SendV4(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size);
|
|
|
|
virtual UInt_64 ReceiveV6(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const;
|
|
|
|
virtual UInt_64 ReceiveV4(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const;
|
|
};
|
|
}
|