...
1
2
3
4
5 package icmp
6
7 import (
8 "golang.org/x/net/internal/iana"
9 "golang.org/x/net/ipv4"
10 "golang.org/x/net/ipv6"
11 )
12
13
14
15 type DstUnreach struct {
16 Data []byte
17 Extensions []Extension
18 }
19
20
21 func (p *DstUnreach) Len(proto int) int {
22 if p == nil {
23 return 0
24 }
25 l, _ := multipartMessageBodyDataLen(proto, true, p.Data, p.Extensions)
26 return l
27 }
28
29
30 func (p *DstUnreach) Marshal(proto int) ([]byte, error) {
31 var typ Type
32 switch proto {
33 case iana.ProtocolICMP:
34 typ = ipv4.ICMPTypeDestinationUnreachable
35 case iana.ProtocolIPv6ICMP:
36 typ = ipv6.ICMPTypeDestinationUnreachable
37 default:
38 return nil, errInvalidProtocol
39 }
40 if !validExtensions(typ, p.Extensions) {
41 return nil, errInvalidExtension
42 }
43 return marshalMultipartMessageBody(proto, true, p.Data, p.Extensions)
44 }
45
46
47
48 func parseDstUnreach(proto int, typ Type, b []byte) (MessageBody, error) {
49 if len(b) < 4 {
50 return nil, errMessageTooShort
51 }
52 p := &DstUnreach{}
53 var err error
54 p.Data, p.Extensions, err = parseMultipartMessageBody(proto, typ, b)
55 if err != nil {
56 return nil, err
57 }
58 return p, nil
59 }
60
View as plain text