...
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 type TimeExceeded struct {
15 Data []byte
16 Extensions []Extension
17 }
18
19
20 func (p *TimeExceeded) Len(proto int) int {
21 if p == nil {
22 return 0
23 }
24 l, _ := multipartMessageBodyDataLen(proto, true, p.Data, p.Extensions)
25 return l
26 }
27
28
29 func (p *TimeExceeded) Marshal(proto int) ([]byte, error) {
30 var typ Type
31 switch proto {
32 case iana.ProtocolICMP:
33 typ = ipv4.ICMPTypeTimeExceeded
34 case iana.ProtocolIPv6ICMP:
35 typ = ipv6.ICMPTypeTimeExceeded
36 default:
37 return nil, errInvalidProtocol
38 }
39 if !validExtensions(typ, p.Extensions) {
40 return nil, errInvalidExtension
41 }
42 return marshalMultipartMessageBody(proto, true, p.Data, p.Extensions)
43 }
44
45
46 func parseTimeExceeded(proto int, typ Type, b []byte) (MessageBody, error) {
47 if len(b) < 4 {
48 return nil, errMessageTooShort
49 }
50 p := &TimeExceeded{}
51 var err error
52 p.Data, p.Extensions, err = parseMultipartMessageBody(proto, typ, b)
53 if err != nil {
54 return nil, err
55 }
56 return p, nil
57 }
58
View as plain text