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.
8 "golang.org/x/net/internal/iana"
9 "golang.org/x/net/ipv4"
10 "golang.org/x/net/ipv6"
13 // A DstUnreach represents an ICMP destination unreachable message
15 type DstUnreach struct {
16 Data []byte // data, known as original datagram field
17 Extensions []Extension // extensions
20 // Len implements the Len method of MessageBody interface.
21 func (p *DstUnreach) Len(proto int) int {
25 l, _ := multipartMessageBodyDataLen(proto, true, p.Data, p.Extensions)
29 // Marshal implements the Marshal method of MessageBody interface.
30 func (p *DstUnreach) Marshal(proto int) ([]byte, error) {
33 case iana.ProtocolICMP:
34 typ = ipv4.ICMPTypeDestinationUnreachable
35 case iana.ProtocolIPv6ICMP:
36 typ = ipv6.ICMPTypeDestinationUnreachable
38 return nil, errInvalidProtocol
40 if !validExtensions(typ, p.Extensions) {
41 return nil, errInvalidExtension
43 return marshalMultipartMessageBody(proto, true, p.Data, p.Extensions)
46 // parseDstUnreach parses b as an ICMP destination unreachable message
48 func parseDstUnreach(proto int, typ Type, b []byte) (MessageBody, error) {
50 return nil, errMessageTooShort
54 p.Data, p.Extensions, err = parseMultipartMessageBody(proto, typ, b)