mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-30 05:25:35 +00:00
71029cea2d
This updates all source files to use a new standard header for copyright and license declaration. Notably, copyright no longer includes a date, and we now use the standard SPDX-License-Identifier header. This commit was done almost entirely mechanically with perl, and then some minimal manual fixes. Updates #6865 Signed-off-by: Will Norris <will@tailscale.com>
29 lines
876 B
Go
29 lines
876 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package packet
|
|
|
|
import (
|
|
crand "crypto/rand"
|
|
|
|
"encoding/binary"
|
|
)
|
|
|
|
// ICMPEchoPayload generates a new random ID/Sequence pair, and returns a uint32
|
|
// derived from them, along with the id, sequence and given payload in a buffer.
|
|
// It returns an error if the random source could not be read.
|
|
func ICMPEchoPayload(payload []byte) (idSeq uint32, buf []byte) {
|
|
buf = make([]byte, len(payload)+4)
|
|
|
|
// make a completely random id/sequence combo, which is very unlikely to
|
|
// collide with a running ping sequence on the host system. Errors are
|
|
// ignored, that would result in collisions, but errors reading from the
|
|
// random device are rare, and will cause this process universe to soon end.
|
|
crand.Read(buf[:4])
|
|
|
|
idSeq = binary.LittleEndian.Uint32(buf)
|
|
copy(buf[4:], payload)
|
|
|
|
return
|
|
}
|