From 1ef6cf53a2aa8fbdc779aea66558fd8ee8220c5c Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sun, 8 Nov 2020 11:52:32 +0100 Subject: [PATCH] Add endian-correctness to TCPSend&Rcv (parallel to the Launcher commit) --- src/Network/TCPHandler.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Network/TCPHandler.cpp b/src/Network/TCPHandler.cpp index d06fcf7..fd1067c 100644 --- a/src/Network/TCPHandler.cpp +++ b/src/Network/TCPHandler.cpp @@ -12,7 +12,8 @@ void TCPSend(Client*c,const std::string&Data){ Assert(c); if(c == nullptr)return; - auto Size = int32_t(Data.size()); + // Size is BIG ENDIAN now, use only for header! + auto Size = htonl(int32_t(Data.size())); std::string Send(4,0); memcpy(&Send[0],&Size,sizeof(Size)); Send += Data; @@ -61,6 +62,8 @@ void TCPRcv(Client*c){ #else BytesRcv = recv(c->GetTCPSock(), reinterpret_cast(&Header), sizeof(Header), 0); #endif + // convert back to host endianness + Header = ntohl(Header); #ifdef DEBUG //debug(std::string(__func__) + Sec(": expecting ") + std::to_string(Header) + Sec(" bytes.")); #endif // DEBUG