go test: don't rely on undefined append behavior

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jonathan Rudenberg 2016-07-07 07:58:30 -04:00 committed by Jason A. Donenfeld
parent 49ea3d5cf4
commit 2a9625acf6

View file

@ -118,15 +118,13 @@ func main() {
Dst: net.IPv4(10, 189, 129, 1), Dst: net.IPv4(10, 189, 129, 1),
}).Marshal() }).Marshal()
binary.BigEndian.PutUint16(pingHeader[2:], uint16(ipv4.HeaderLen+len(pingMessage))) // fix the length endianness on BSDs binary.BigEndian.PutUint16(pingHeader[2:], uint16(ipv4.HeaderLen+len(pingMessage))) // fix the length endianness on BSDs
binary.BigEndian.PutUint16(pingHeader[10:], ipChecksum(append(pingHeader, pingMessage...))) pingData := append(pingHeader, pingMessage...)
if err != nil { binary.BigEndian.PutUint16(pingData[10:], ipChecksum(pingData))
panic(err)
}
pingPacket := make([]byte, 13) pingPacket := make([]byte, 13)
pingPacket[0] = 4 // Type: Data pingPacket[0] = 4 // Type: Data
binary.LittleEndian.PutUint32(pingPacket[1:], theirIndex) binary.LittleEndian.PutUint32(pingPacket[1:], theirIndex)
binary.LittleEndian.PutUint64(pingPacket[5:], 0) // Nonce binary.LittleEndian.PutUint64(pingPacket[5:], 0) // Nonce
pingPacket = sendCipher.Encrypt(pingPacket, nil, append(pingHeader, pingMessage...)) pingPacket = sendCipher.Encrypt(pingPacket, nil, pingData)
if _, err := conn.Write(pingPacket); err != nil { if _, err := conn.Write(pingPacket); err != nil {
log.Fatalf("error writing ping message: %s", err) log.Fatalf("error writing ping message: %s", err)
} }