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 import "encoding/binary"
9 // An Echo represents an ICMP echo request or reply message body.
12 Seq int // sequence number
16 // Len implements the Len method of MessageBody interface.
17 func (p *Echo) Len(proto int) int {
21 return 4 + len(p.Data)
24 // Marshal implements the Marshal method of MessageBody interface.
25 func (p *Echo) Marshal(proto int) ([]byte, error) {
26 b := make([]byte, 4+len(p.Data))
27 binary.BigEndian.PutUint16(b[:2], uint16(p.ID))
28 binary.BigEndian.PutUint16(b[2:4], uint16(p.Seq))
33 // parseEcho parses b as an ICMP echo request or reply message body.
34 func parseEcho(proto int, b []byte) (MessageBody, error) {
37 return nil, errMessageTooShort
39 p := &Echo{ID: int(binary.BigEndian.Uint16(b[:2])), Seq: int(binary.BigEndian.Uint16(b[2:4]))}
41 p.Data = make([]byte, bodyLen-4)