Checksum simplification proposal (#29)

* Simplified checksum calculation and verification

* Fixed tests

* UDP: using NewBoundedFrame to create a Frame instance limited to the actual frame size.

* Minor: renamed some functions

* Commented and made more readable consecutive SetCRC calls.

* Fixed icmp checksum calculation after rebase

* Replaced NewBoundedFrame with explicit validation
This commit is contained in:
ddirect
2026-02-05 22:35:42 +02:00
committed by GitHub
parent cd51bd6c3f
commit fba97c990a
13 changed files with 139 additions and 228 deletions
+5 -2
View File
@@ -141,6 +141,8 @@ func TestIPv4TCPChecksum(t *testing.T) {
t.Fatal(err)
}
wantCRC := ifrm.CRC()
// Zero the CRC field so its value does not add to the final result.
ifrm.SetCRC(0)
gotCRC := ifrm.CalculateHeaderCRC()
if wantCRC != gotCRC {
t.Errorf("IPv4 CRC miscalculated. want %x, got %x", wantCRC, gotCRC)
@@ -148,8 +150,9 @@ func TestIPv4TCPChecksum(t *testing.T) {
wantCRC = tfrm.CRC()
var crc lneto.CRC791
ifrm.CRCWriteTCPPseudo(&crc)
tfrm.CRCWrite(&crc)
gotCRC = crc.Sum16()
// Zero the CRC field so its value does not add to the final result.
tfrm.SetCRC(0)
gotCRC = crc.PayloadSum16(tfrm.RawData())
if wantCRC != gotCRC {
t.Errorf("TCP CRC miscalculated. want %x, got %x", wantCRC, gotCRC)
}