mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-06-18 22:50:59 +00:00
Add endian-correctness to TCPSend&Rcv
This commit is contained in:
@@ -29,10 +29,12 @@ void TCPSend(const std::string&Data){
|
|||||||
Terminate = true;
|
Terminate = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto Size = int32_t(Data.size());
|
// Size is BIG-ENDIAN!
|
||||||
|
auto Size = htonl(int32_t(Data.size()));
|
||||||
std::string Send(4,0);
|
std::string Send(4,0);
|
||||||
memcpy(&Send[0],&Size,sizeof(Size));
|
memcpy(&Send[0],&Size,sizeof(Size));
|
||||||
Send += Data;
|
Send += Data;
|
||||||
|
// Do not use Size before this point for anything but the header
|
||||||
Size = int32_t(Send.size());
|
Size = int32_t(Send.size());
|
||||||
int32_t Sent = 0,Temp;
|
int32_t Sent = 0,Temp;
|
||||||
do{
|
do{
|
||||||
@@ -50,7 +52,8 @@ void TCPRcv(){
|
|||||||
}
|
}
|
||||||
static int32_t Header,BytesRcv,Temp;
|
static int32_t Header,BytesRcv,Temp;
|
||||||
BytesRcv = recv(TCPSock, reinterpret_cast<char*>(&Header), sizeof(Header),0);
|
BytesRcv = recv(TCPSock, reinterpret_cast<char*>(&Header), sizeof(Header),0);
|
||||||
|
// convert back to LITTLE ENDIAN
|
||||||
|
Header = ntohl(Header);
|
||||||
if(!CheckBytes(BytesRcv))return;
|
if(!CheckBytes(BytesRcv))return;
|
||||||
char* Data = new char[Header];
|
char* Data = new char[Header];
|
||||||
BytesRcv = 0;
|
BytesRcv = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user