mirror of
https://github.com/soypat/lneto.git
synced 2026-09-02 04:49:02 +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:
+10
-8
@@ -136,23 +136,25 @@ func (ifrm Frame) CalculateHeaderCRC() uint16 {
|
||||
}
|
||||
|
||||
func (ifrm Frame) CRCWriteHeader(crc *lneto.CRC791) {
|
||||
crc.Write(ifrm.buf[0:10])
|
||||
crc.Write(ifrm.buf[12:20])
|
||||
crc.WriteEven(ifrm.buf[:20])
|
||||
}
|
||||
|
||||
func (ifrm Frame) CRCWriteTCPPseudo(crc *lneto.CRC791) {
|
||||
crc.Write(ifrm.SourceAddr()[:])
|
||||
crc.Write(ifrm.DestinationAddr()[:])
|
||||
crc.AddUint16(ifrm.TotalLength() - 4*uint16(ifrm.ihl()))
|
||||
crc.WriteEven(ifrm.sourceAndDestinationAddr())
|
||||
crc.AddUint16(ifrm.TotalLength() - uint16(ifrm.HeaderLength()))
|
||||
crc.AddUint16(uint16(ifrm.Protocol()))
|
||||
}
|
||||
|
||||
func (ifrm Frame) CRCWriteUDPPseudo(crc *lneto.CRC791) {
|
||||
crc.Write(ifrm.SourceAddr()[:])
|
||||
crc.Write(ifrm.DestinationAddr()[:])
|
||||
func (ifrm Frame) CRCWriteUDPPseudo(crc *lneto.CRC791, udpLength uint16) {
|
||||
crc.WriteEven(ifrm.sourceAndDestinationAddr())
|
||||
crc.AddUint16(udpLength)
|
||||
crc.AddUint16(uint16(ifrm.Protocol()))
|
||||
}
|
||||
|
||||
func (ifrm Frame) sourceAndDestinationAddr() []byte {
|
||||
return ifrm.buf[12:20]
|
||||
}
|
||||
|
||||
// SourceAddr returns pointer to the source IPv4 address in the IP header.
|
||||
func (ifrm Frame) SourceAddr() *[4]byte {
|
||||
return (*[4]byte)(ifrm.buf[12:16])
|
||||
|
||||
Reference in New Issue
Block a user