mirror of
https://github.com/soypat/lneto.git
synced 2026-09-02 12:59:04 +00:00
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:
+5
-2
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user