mirror of
https://github.com/soypat/lneto.git
synced 2026-09-09 08:19:09 +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:
@@ -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:]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user