blob: 75db991dfd341511a5d628e3faf6395f5ada3ada [file] [log] [blame]
David K. Bainbridge215e0242017-09-05 23:18:24 -07001// 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.
4
5package icmp
6
7// A DstUnreach represents an ICMP destination unreachable message
8// body.
9type DstUnreach struct {
10 Data []byte // data, known as original datagram field
11 Extensions []Extension // extensions
12}
13
14// Len implements the Len method of MessageBody interface.
15func (p *DstUnreach) Len(proto int) int {
16 if p == nil {
17 return 0
18 }
19 l, _ := multipartMessageBodyDataLen(proto, p.Data, p.Extensions)
20 return 4 + l
21}
22
23// Marshal implements the Marshal method of MessageBody interface.
24func (p *DstUnreach) Marshal(proto int) ([]byte, error) {
25 return marshalMultipartMessageBody(proto, p.Data, p.Extensions)
26}
27
28// parseDstUnreach parses b as an ICMP destination unreachable message
29// body.
30func parseDstUnreach(proto int, b []byte) (MessageBody, error) {
31 if len(b) < 4 {
32 return nil, errMessageTooShort
33 }
34 p := &DstUnreach{}
35 var err error
36 p.Data, p.Extensions, err = parseMultipartMessageBody(proto, b)
37 if err != nil {
38 return nil, err
39 }
40 return p, nil
41}