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
-8
View File
@@ -3,8 +3,6 @@ package icmpv4
import (
"encoding/binary"
"errors"
"github.com/soypat/lneto"
)
type Type uint8
@@ -87,12 +85,6 @@ func (frm Frame) SetCRC(crc uint16) {
binary.BigEndian.PutUint16(frm.buf[2:4], crc)
}
// CRCWrite calculates the checksum of the ICMP packet. Treats the checksum field as zero as per RFC 792.
func (frm Frame) CRCWrite(crc *lneto.CRC791) {
crc.AddUint16(binary.BigEndian.Uint16(frm.buf[0:2]))
crc.Write(frm.buf[4:])
}
func (frm Frame) payload() []byte {
return frm.buf[4:]
}