1 // Copyright 2014 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 // A PacketTooBig represents an ICMP packet too big message body.
10 type PacketTooBig struct {
11 MTU int // maximum transmission unit of the nexthop link
12 Data []byte // data, known as original datagram field
15 // Len implements the Len method of MessageBody interface.
16 func (p *PacketTooBig) Len(proto int) int {
20 return 4 + len(p.Data)
23 // Marshal implements the Marshal method of MessageBody interface.
24 func (p *PacketTooBig) Marshal(proto int) ([]byte, error) {
25 b := make([]byte, 4+len(p.Data))
26 binary.BigEndian.PutUint32(b[:4], uint32(p.MTU))
31 // parsePacketTooBig parses b as an ICMP packet too big message body.
32 func parsePacketTooBig(proto int, b []byte) (MessageBody, error) {
35 return nil, errMessageTooShort
37 p := &PacketTooBig{MTU: int(binary.BigEndian.Uint32(b[:4]))}
39 p.Data = make([]byte, bodyLen-4)