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 "golang.org/x/net/internal/iana"
9
// A ParamProb represents an ICMP parameter problem message body.
10
type ParamProb struct {
11
Pointer uintptr // offset within the data where the error was detected
12
Data []byte // data, known as original datagram field
13
Extensions []Extension // extensions
16
// Len implements the Len method of MessageBody interface.
17
func (p *ParamProb) Len(proto int) int {
21
l, _ := multipartMessageBodyDataLen(proto, p.Data, p.Extensions)
25
// Marshal implements the Marshal method of MessageBody interface.
26
func (p *ParamProb) Marshal(proto int) ([]byte, error) {
27
if proto == iana.ProtocolIPv6ICMP {
28
b := make([]byte, 4+p.Len(proto))
29
b[0], b[1], b[2], b[3] = byte(p.Pointer>>24), byte(p.Pointer>>16), byte(p.Pointer>>8), byte(p.Pointer)
33
b, err := marshalMultipartMessageBody(proto, p.Data, p.Extensions)
37
b[0] = byte(p.Pointer)
41
// parseParamProb parses b as an ICMP parameter problem message body.
42
func parseParamProb(proto int, b []byte) (MessageBody, error) {
44
return nil, errMessageTooShort
47
if proto == iana.ProtocolIPv6ICMP {
48
p.Pointer = uintptr(b[0])<<24 | uintptr(b[1])<<16 | uintptr(b[2])<<8 | uintptr(b[3])
49
p.Data = make([]byte, len(b)-4)
53
p.Pointer = uintptr(b[0])
55
p.Data, p.Extensions, err = parseMultipartMessageBody(proto, b)