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.
9 "golang.org/x/net/internal/iana"
12 // A ParamProb represents an ICMP parameter problem message body.
13 type ParamProb struct {
14 Pointer uintptr // offset within the data where the error was detected
15 Data []byte // data, known as original datagram field
16 Extensions []Extension // extensions
19 // Len implements the Len method of MessageBody interface.
20 func (p *ParamProb) Len(proto int) int {
24 l, _ := multipartMessageBodyDataLen(proto, p.Data, p.Extensions)
28 // Marshal implements the Marshal method of MessageBody interface.
29 func (p *ParamProb) Marshal(proto int) ([]byte, error) {
30 if proto == iana.ProtocolIPv6ICMP {
31 b := make([]byte, p.Len(proto))
32 binary.BigEndian.PutUint32(b[:4], uint32(p.Pointer))
36 b, err := marshalMultipartMessageBody(proto, p.Data, p.Extensions)
40 b[0] = byte(p.Pointer)
44 // parseParamProb parses b as an ICMP parameter problem message body.
45 func parseParamProb(proto int, b []byte) (MessageBody, error) {
47 return nil, errMessageTooShort
50 if proto == iana.ProtocolIPv6ICMP {
51 p.Pointer = uintptr(binary.BigEndian.Uint32(b[:4]))
52 p.Data = make([]byte, len(b)-4)
56 p.Pointer = uintptr(b[0])
58 p.Data, p.Extensions, err = parseMultipartMessageBody(proto, b)