34 lines
780 B
Go
34 lines
780 B
Go
package inetcksum
|
|
|
|
import (
|
|
`encoding/binary`
|
|
)
|
|
|
|
const (
|
|
// EmptyCksum is returned for checksums of 0-length byte slices/buffers.
|
|
EmptyCksum uint16 = 0xffff
|
|
)
|
|
|
|
const (
|
|
/*
|
|
cksumMask is AND'd with a checksum to get the "carried ones"
|
|
(the lower 16 bits before folding carries).
|
|
*/
|
|
cksumMask uint32 = 0x0000ffff
|
|
/*
|
|
cksumShift is used in the "carried-ones folding";
|
|
it's the number of bits to right-shift the carry-over.
|
|
*/
|
|
cksumShift uint32 = 0x00000010
|
|
/*
|
|
padShift is used to "pad out" a checksum for odd-length buffers by left-shifting.
|
|
It positions the high-byte of a 16-byte "word" (big-endian, as per ord below).
|
|
*/
|
|
padShift uint32 = 0x00000008
|
|
)
|
|
|
|
var (
|
|
// ord is the byte order used by the Internet Checksum.
|
|
ord binary.ByteOrder = binary.BigEndian
|
|
)
|