Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

40 řádky
1.1 KiB

  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, 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, p.Data, p.Extensions)
  21. }
  22. // parseTimeExceeded parses b as an ICMP time exceeded message body.
  23. func parseTimeExceeded(proto int, 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, b)
  30. if err != nil {
  31. return nil, err
  32. }
  33. return p, nil
  34. }