Example #1
0
// ICMPv6 Checksum calculation
// Adapted from https://github.com/golang/net/blob/bdcab5d1425b3bc74ab0f2be70acb9e4a2b2f73e/icmp/message.go#L35
func MakeChecksum(packet Message, src, dst net.IP) uint16 {
	b := packet.Marshal()
	// Create new pseudo header
	pHeader := ipv6.NewPseudoHeader(len(b), 0x3a, src, dst)
	// append icmp bytes to pseudo header
	b = append(pHeader.Marshal(), b...)
	// Make checksum
	return csum(b)
}
Example #2
0
func VerifyChecksum(h *ipv6.Header, b []byte) bool {
	// get checksum from package
	co := binary.BigEndian.Uint16(b[2:4])
	// Create pseudo header
	ph := ipv6.NewPseudoHeader(h.PayloadLen, h.NextHeader, h.Src, h.Dst)
	// Set checksum to 0x0
	b[2] = 0
	b[3] = 0
	// make packet
	b = append(ph.Marshal(), b...)
	// calculate checksum and compare
	return co == csum(b)
}