github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/net/icmp/dstunreach.go (about)

     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.
     4  
     5  package icmp
     6  
     7  // A DstUnreach represents an ICMP destination unreachable message
     8  // body.
     9  type 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.
    15  func (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.
    24  func (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.
    30  func 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  }