Kernel: Fix checksum for packets with odd number of bytes

This commit is contained in:
Bananymous 2024-02-09 01:20:40 +02:00
parent f117027175
commit d452cf4170
1 changed files with 2 additions and 0 deletions

View File

@ -38,6 +38,8 @@ namespace Kernel
checksum += BAN::host_to_network_endian(reinterpret_cast<const uint16_t*>(&pseudo_header)[i]);
for (size_t i = 0; i < packet.size() / sizeof(uint16_t); i++)
checksum += BAN::host_to_network_endian(reinterpret_cast<const uint16_t*>(packet.data())[i]);
if (packet.size() % 2)
checksum += (uint16_t)packet[packet.size() - 1] << 8;
while (checksum >> 16)
checksum = (checksum >> 16) + (checksum & 0xFFFF);
return ~(uint16_t)checksum;