Improve checksum usages

This commit is contained in:
世界 2025-08-27 11:03:17 +08:00
parent f9bbb15bfb
commit adc106bcf6
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
9 changed files with 23 additions and 45 deletions

View file

@ -479,7 +479,9 @@ func (b IPv4) SetDestinationAddress(addr tcpip.Address) {
// CalculateChecksum calculates the checksum of the IPv4 header.
func (b IPv4) CalculateChecksum() uint16 {
return checksum.Checksum(b[:b.HeaderLength()], 0)
xsum0 := checksum.Checksum(b[:xsum], 0)
xsum0 = checksum.Checksum(b[xsum+2:b.HeaderLength()], xsum0)
return xsum0
}
// Encode encodes all the fields of the IPv4 header.