Fix checksum changes

This commit is contained in:
世界 2025-08-27 15:45:18 +08:00
parent adc106bcf6
commit ff49ece55d
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
4 changed files with 11 additions and 4 deletions

View file

@ -479,6 +479,7 @@ 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
@ -573,7 +574,8 @@ func (b IPv4) IsChecksumValid() bool {
// same set of octets, including the checksum field. If the result
// is all 1 bits (-0 in 1's complement arithmetic), the check
// succeeds.
return b.CalculateChecksum() == 0xffff
//return b.CalculateChecksum() == 0xffff
return checksum.Checksum(b[:b.HeaderLength()], 0) == 0xffff
}
// IsV4MulticastAddress determines if the provided address is an IPv4 multicast