github.com/metacubex/sing-tun@v0.2.7-0.20240512075008-89e7c6208eec/internal/clashtcpip/tcpip_compat.go (about)

     1  package clashtcpip
     2  
     3  func SumCompat(b []byte) (sum uint32) {
     4  	n := len(b)
     5  	if n&1 != 0 {
     6  		n--
     7  		sum += uint32(b[n]) << 8
     8  	}
     9  
    10  	for i := 0; i < n; i += 2 {
    11  		sum += (uint32(b[i]) << 8) | uint32(b[i+1])
    12  	}
    13  	return
    14  }