Compare commits
11 Commits
v1.0.4-rc.
...
v1.4.0-rc.
Author | SHA1 | Date | |
---|---|---|---|
d41f71f17d | |||
c19c0bc80b | |||
86149d246a | |||
1e55b11eed | |||
ce225b2888 | |||
eb3d345c5a | |||
6cf4977a6c | |||
ae226c9a84 | |||
bf3b063e96 | |||
e071877045 | |||
af90f90156 |
@@ -22,10 +22,9 @@ jobs:
|
||||
- name: Building/Compiling/Installing Project
|
||||
run: |
|
||||
cd ${{ gitea.workspace }}
|
||||
vcpkg install
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -A x64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake ..
|
||||
cmake -A x64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake" ..
|
||||
cmake --build . --config Release
|
||||
cmake --install .
|
||||
|
||||
|
@@ -132,12 +132,12 @@ set(EHS_SOURCES
|
||||
include/ehs/io/socket/TCP.h
|
||||
src/io/socket/SSL.cpp include/ehs/io/socket/SSL.h
|
||||
|
||||
include/ehs/io/socket/ehc/NetUtils.h
|
||||
src/io/socket/EHC.cpp include/ehs/io/socket/EHC.h
|
||||
src/io/socket/ehc/NetFrag.cpp include/ehs/io/socket/ehc/NetFrag.h
|
||||
src/io/socket/ehc/NetEnd.cpp include/ehs/io/socket/ehc/NetEnd.h
|
||||
src/io/socket/ehc/NetSys.cpp include/ehs/io/socket/ehc/NetSys.h
|
||||
src/io/socket/ehc/NetOp.cpp include/ehs/io/socket/ehc/NetOp.h
|
||||
include/ehs/io/socket/ehc/NetUtils.h
|
||||
src/io/socket/EHC.cpp include/ehs/io/socket/EHC.h
|
||||
src/io/socket/ehc/NetFrag.cpp include/ehs/io/socket/ehc/NetFrag.h
|
||||
src/io/socket/ehc/NetEnd.cpp include/ehs/io/socket/ehc/NetEnd.h
|
||||
src/io/socket/ehc/NetSys.cpp include/ehs/io/socket/ehc/NetSys.h
|
||||
src/io/socket/ehc/NetOp.cpp include/ehs/io/socket/ehc/NetOp.h
|
||||
|
||||
src/io/socket/rest/Twitch.cpp include/ehs/io/socket/rest/Twitch.h
|
||||
src/io/socket/rest/TwitchChat.cpp include/ehs/io/socket/rest/TwitchChat.h
|
||||
@@ -193,12 +193,9 @@ set(EHS_SOURCES
|
||||
include/ehs/io/socket/ehc/NetClientCh.h
|
||||
src/io/socket/ehc/NetClientCh.cpp
|
||||
src/io/socket/ehc/NetServerCh.cpp
|
||||
src/io/socket/ehc/NetUtils.cpp
|
||||
src/io/socket/BaseICMP.cpp
|
||||
include/ehs/io/socket/ICMP_LNX.h
|
||||
src/io/socket/ICMP_LNX.cpp
|
||||
include/ehs/io/socket/ICMP.h
|
||||
src/io/socket/ICMP_LNX.cpp
|
||||
src/io/socket/ehc/NetUtils.cpp
|
||||
include/ehs/io/socket/BaseICMP.h src/io/socket/BaseICMP.cpp
|
||||
include/ehs/io/socket/ICMP.h
|
||||
)
|
||||
|
||||
if (IS_OS_WINDOWS)
|
||||
@@ -217,7 +214,9 @@ if (IS_OS_WINDOWS)
|
||||
src/io/COM.cpp include/ehs/io/COM.h
|
||||
src/system/CPU_MSVC_AMD64.asm src/HRNG_MSVC.asm src/Math_MSVC_AMD64.asm
|
||||
src/io/Directory_W32.cpp include/ehs/io/Directory_W32.h
|
||||
include/ehs/io/socket/ICMP_W32.h src/io/socket/ICMP_W32.cpp
|
||||
)
|
||||
|
||||
elseif (IS_OS_LINUX)
|
||||
list(APPEND EHS_SOURCES
|
||||
src/io/socket/UDP_BSD.cpp include/ehs/io/socket/UDP_BSD.h
|
||||
@@ -234,6 +233,7 @@ elseif (IS_OS_LINUX)
|
||||
src/system/User.cpp include/ehs/system/User.h
|
||||
src/io/Directory_LNX.cpp include/ehs/io/Directory_LNX.h
|
||||
src/io/Usb_LNX.cpp include/ehs/io/Usb_LNX.h
|
||||
include/ehs/io/socket/ICMP_LNX.h src/io/socket/ICMP_LNX.cpp
|
||||
)
|
||||
|
||||
#set(LINUX_WINDOW_SYSTEM "Wayland" CACHE STRING "Linux Window System")
|
||||
@@ -262,8 +262,7 @@ endif()
|
||||
#message("${CMAKE_CXX_FLAGS}")
|
||||
|
||||
add_library(EHS_Stc STATIC ${EHS_SOURCES})
|
||||
add_library(EHS_Dyn SHARED ${EHS_SOURCES}
|
||||
include/ehs/io/socket/BaseICMP.h)
|
||||
add_library(EHS_Dyn SHARED ${EHS_SOURCES})
|
||||
add_executable(StrToHash src/StrToHash.cpp)
|
||||
|
||||
target_compile_definitions(EHS_Dyn PRIVATE EHS_LIB_EXPORT)
|
||||
|
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/system/OS.h"
|
||||
|
||||
#ifdef EHS_OS_WINDOWS
|
||||
#include "BaseICMP.h"
|
||||
#include "ICMP_W32.h"
|
||||
#else
|
||||
#include "ICMP_LNX.h"
|
||||
#include "ICMP_LNX.h"
|
||||
#endif
|
33
include/ehs/io/socket/ICMP_W32.h
Normal file
33
include/ehs/io/socket/ICMP_W32.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseICMP.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
class ICMP : public BaseICMP
|
||||
{
|
||||
private:
|
||||
Int_32 hdl;
|
||||
|
||||
public:
|
||||
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;
|
||||
};
|
||||
}
|
@@ -1,8 +1,6 @@
|
||||
#include "ehs/io/socket/BaseICMP.h"
|
||||
#include "ehs/Serializer.h"
|
||||
|
||||
#include <netinet/ip.h>
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
|
||||
|
187
src/io/socket/ICMP_W32.cpp
Normal file
187
src/io/socket/ICMP_W32.cpp
Normal file
@@ -0,0 +1,187 @@
|
||||
#include "ehs/io/socket/ICMP_W32.h"
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#include <iphlpapi.h>
|
||||
|
||||
struct iphdr
|
||||
{
|
||||
u_char ip_hl:4, ip_v:4;
|
||||
u_char ip_tos;
|
||||
u_short ip_len;
|
||||
u_short ip_id;
|
||||
u_short ip_off;
|
||||
u_char ip_ttl;
|
||||
u_char ip_p;
|
||||
u_short ip_sum;
|
||||
in_addr ip_src, ip_dst;
|
||||
};
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
ICMP::ICMP()
|
||||
: hdl(EHS_INVALID_SOCKET)
|
||||
{
|
||||
}
|
||||
|
||||
ICMP::ICMP(const IP version)
|
||||
: BaseICMP(version)
|
||||
{
|
||||
hdl = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
|
||||
if (hdl < 0)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to create ICMP socket with error #" + Str_8::FromNum(errno) + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
EHS_LOG_SUCCESS();
|
||||
}
|
||||
|
||||
ICMP::ICMP(ICMP &&icmp) noexcept
|
||||
: BaseICMP((BaseICMP &&)icmp), hdl(icmp.hdl)
|
||||
{
|
||||
icmp.hdl = EHS_INVALID_SOCKET;
|
||||
}
|
||||
|
||||
ICMP::ICMP(const ICMP &icmp)
|
||||
: BaseICMP(icmp), hdl(icmp.hdl)
|
||||
{
|
||||
}
|
||||
|
||||
ICMP & ICMP::operator=(ICMP &&icmp) noexcept
|
||||
{
|
||||
if (this == &icmp)
|
||||
return *this;
|
||||
|
||||
BaseICMP::operator=((BaseICMP &&)icmp);
|
||||
|
||||
hdl = icmp.hdl;
|
||||
|
||||
icmp.hdl = EHS_INVALID_SOCKET;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ICMP & ICMP::operator=(const ICMP &icmp)
|
||||
{
|
||||
if (this == &icmp)
|
||||
return *this;
|
||||
|
||||
BaseICMP::operator=(icmp);
|
||||
|
||||
hdl = icmp.hdl;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
UInt_64 ICMP::Send(const Str_8 &address, ICMP_Header header, const Byte *data, const UInt_64 size)
|
||||
{
|
||||
if (!IsValid())
|
||||
{
|
||||
EHS_LOG_INT(LogType::WARN, 0, "Socket is not initialized.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
header.checksum = 0;
|
||||
|
||||
Serializer<UInt_64> payload(Endianness::LE);
|
||||
payload.Write(header);
|
||||
payload.Resize(payload.Size() + size);
|
||||
|
||||
Util::Copy(&payload[payload.GetOffset()], data, size);
|
||||
|
||||
payload.SetOffset(payload.GetOffset() + size);
|
||||
|
||||
header.checksum = ComputeChecksum((UInt_16 *)&payload[0], payload.Size());
|
||||
|
||||
payload.SetOffset(0);
|
||||
payload.Write(header);
|
||||
payload.SetOffset(payload.Size());
|
||||
|
||||
sockaddr_in dst_addr = {};
|
||||
dst_addr.sin_family = AF_INET;
|
||||
inet_pton(AF_INET, address, &(dst_addr.sin_addr));
|
||||
|
||||
SInt_64 sent = sendto(hdl, (const char *)&payload[0], payload.Size(), 0, (sockaddr *)&dst_addr, sizeof(dst_addr));
|
||||
if (sent < 0)
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to send packet with error #" + Str_8::FromNum(errno) + ".");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EHS_LOG_SUCCESS();
|
||||
|
||||
return sent;
|
||||
}
|
||||
|
||||
UInt_64 ICMP::Receive(Str_8 &address, ICMP_Header header, Serializer<UInt_64> &data)
|
||||
{
|
||||
if (!IsValid())
|
||||
{
|
||||
EHS_LOG_INT(LogType::WARN, 0, "Socket is not initialized.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Serializer<UInt_64> payload(Endianness::LE);
|
||||
payload.Resize(1500);
|
||||
|
||||
sockaddr_in remote = {};
|
||||
socklen_t from_len = sizeof(remote);
|
||||
|
||||
SInt_64 recv = recvfrom(hdl, (char *)&payload[0], 1500, 0, (sockaddr *)&remote, &from_len);
|
||||
if (recv < 0)
|
||||
{
|
||||
int code = errno;
|
||||
if (code == EAGAIN)
|
||||
EHS_LOG_SUCCESS();
|
||||
else
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to receive packet with error #" + Str_8::FromNum(code) + ".");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
payload.Resize(recv);
|
||||
|
||||
char tmpAddr[INET_ADDRSTRLEN];
|
||||
|
||||
if (!inet_ntop(remote.sin_family, &remote.sin_addr, tmpAddr, INET_ADDRSTRLEN))
|
||||
{
|
||||
EHS_LOG_INT(LogType::ERR, 1, "Failed to convert IPv4 address with error #" + Str_8::FromNum(errno) + ".");
|
||||
|
||||
return recv;
|
||||
}
|
||||
|
||||
address = tmpAddr;
|
||||
iphdr ipHeader = payload.Read<iphdr>();
|
||||
header = payload.Read<ICMP_Header>();
|
||||
data = Serializer<UInt_64>(payload.GetEndianness(), &payload[payload.GetOffset()], payload.Size() - payload.GetOffset());
|
||||
|
||||
EHS_LOG_SUCCESS();
|
||||
|
||||
return recv;
|
||||
}
|
||||
|
||||
void ICMP::SetReceiveTimeout(UInt_64 timeout)
|
||||
{
|
||||
timeval result = {};
|
||||
result.tv_sec = (long)timeout;
|
||||
result.tv_usec = 0;
|
||||
|
||||
if (setsockopt(hdl, SOL_SOCKET, SO_RCVTIMEO, (const char *)&result, sizeof(result)) < 0)
|
||||
{
|
||||
EHS_LOG_INT(LogType::WARN, 0, "Failed to set receive timeout with error #" + Str_8::FromNum(errno) + ".");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
EHS_LOG_SUCCESS();
|
||||
}
|
||||
|
||||
bool ICMP::IsValid() const
|
||||
{
|
||||
return hdl != EHS_INVALID_SOCKET;
|
||||
}
|
||||
}
|
@@ -43,4 +43,9 @@ namespace ehs
|
||||
void CPU::GetBrand(Char_8* input)
|
||||
{
|
||||
}
|
||||
|
||||
UInt_8 CPU::GetCacheLineSize()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user