timeexceeded.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. package icmp
  5. // A TimeExceeded represents an ICMP time exceeded message body.
  6. type TimeExceeded struct {
  7. Data []byte // data, known as original datagram field
  8. Extensions []Extension // extensions
  9. }
  10. // Len implements the Len method of MessageBody interface.
  11. func (p *TimeExceeded) Len(proto int) int {
  12. if p == nil {
  13. return 0
  14. }
  15. l, _ := multipartMessageBodyDataLen(proto, true, p.Data, p.Extensions)
  16. return 4 + l
  17. }
  18. // Marshal implements the Marshal method of MessageBody interface.
  19. func (p *TimeExceeded) Marshal(proto int) ([]byte, error) {
  20. return marshalMultipartMessageBody(proto, true, p.Data, p.Extensions)
  21. }
  22. // parseTimeExceeded parses b as an ICMP time exceeded message body.
  23. func parseTimeExceeded(proto int, typ Type, b []byte) (MessageBody, error) {
  24. if len(b) < 4 {
  25. return nil, errMessageTooShort
  26. }
  27. p := &TimeExceeded{}
  28. var err error
  29. p.Data, p.Extensions, err = parseMultipartMessageBody(proto, typ, b)
  30. if err != nil {
  31. return nil, err
  32. }
  33. return p, nil
  34. }