1
// Copyright 2012 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
7
// An Echo represents an ICMP echo request or reply message body.
10
Seq int // sequence number
14
// Len implements the Len method of MessageBody interface.
15
func (p *Echo) Len(proto int) int {
19
return 4 + len(p.Data)
22
// Marshal implements the Marshal method of MessageBody interface.
23
func (p *Echo) Marshal(proto int) ([]byte, error) {
24
b := make([]byte, 4+len(p.Data))
25
b[0], b[1] = byte(p.ID>>8), byte(p.ID)
26
b[2], b[3] = byte(p.Seq>>8), byte(p.Seq)
31
// parseEcho parses b as an ICMP echo request or reply message body.
32
func parseEcho(proto int, b []byte) (MessageBody, error) {
35
return nil, errMessageTooShort
37
p := &Echo{ID: int(b[0])<<8 | int(b[1]), Seq: int(b[2])<<8 | int(b[3])}
39
p.Data = make([]byte, bodyLen-4)