DEV9: Correct alignment calculation in Sockets

This commit is contained in:
TheLastRar 2024-12-03 22:28:12 +00:00 committed by Ty
parent 00f4cd5252
commit f317ba327c
2 changed files with 6 additions and 4 deletions

View File

@ -4,6 +4,7 @@
#include "IP_Packet.h" #include "IP_Packet.h"
#include "DEV9/PacketReader/NetLib.h" #include "DEV9/PacketReader/NetLib.h"
#include "common/BitUtils.h"
#include "common/Console.h" #include "common/Console.h"
namespace PacketReader::IP namespace PacketReader::IP
@ -209,8 +210,8 @@ namespace PacketReader::IP
for (size_t i = 0; i < options.size(); i++) for (size_t i = 0; i < options.size(); i++)
opOffset += options[i]->GetLength(); opOffset += options[i]->GetLength();
opOffset += opOffset % 4; //needs to be a whole number of 32bits //needs to be a whole number of 32bits
headerLength = opOffset; headerLength = Common::AlignUpPow2(opOffset, 4);
} }
void IP_Packet::CalculateChecksum() void IP_Packet::CalculateChecksum()

View File

@ -4,6 +4,7 @@
#include "TCP_Packet.h" #include "TCP_Packet.h"
#include "DEV9/PacketReader/NetLib.h" #include "DEV9/PacketReader/NetLib.h"
#include "common/BitUtils.h"
#include "common/Console.h" #include "common/Console.h"
namespace PacketReader::IP::TCP namespace PacketReader::IP::TCP
@ -232,8 +233,8 @@ namespace PacketReader::IP::TCP
for (size_t i = 0; i < options.size(); i++) for (size_t i = 0; i < options.size(); i++)
opOffset += options[i]->GetLength(); opOffset += options[i]->GetLength();
opOffset += opOffset % 4; //needs to be a whole number of 32bits //needs to be a whole number of 32bits
headerLength = opOffset; headerLength = Common::AlignUpPow2(opOffset, 4);
//Also write into dataOffsetAndNS_Flag //Also write into dataOffsetAndNS_Flag
u8 ns = dataOffsetAndNS_Flag & 1; u8 ns = dataOffsetAndNS_Flag & 1;