EHS/include/ehs/io/socket/ICMP_LNX.h

62 lines
1.3 KiB
C++

#pragma once
#include "BaseICMP.h"
#include <netinet/in.h>
namespace ehs
{
struct PseudoICMPv6_Header
{
sockaddr_in6 src;
sockaddr_in6 dst;
UInt_32 length;
};
class ICMP final : public BaseICMP
{
private:
Int_32 hdl;
sockaddr_in6 src;
public:
~ICMP();
ICMP();
ICMP(IP version);
ICMP(ICMP &&icmp) noexcept;
ICMP(const ICMP &icmp);
ICMP &operator=(ICMP &&icmp) noexcept;
ICMP &operator=(const ICMP &icmp);
UInt_64 Send(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size) override;
UInt_64 Receive(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) override;
void SetReceiveTimeout(UInt_64 timeout) override;
bool IsValid() const override;
private:
static bool IsLinkLocal(const in6_addr &addr);
static sockaddr_in6 RetrieveSrcAddress();
static UInt_32 CalculatePseudoHeaderChecksum(const PseudoICMPv6_Header &header);
UInt_16 ComputeChecksumV6(UInt_16* buffer, Size length, const sockaddr_in6& dst);
UInt_64 SendV6(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size);
UInt_64 SendV4(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size);
UInt_64 ReceiveV6(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const;
UInt_64 ReceiveV4(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const;
};
}