interface_announce.go 805 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2016 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. //go:build dragonfly || freebsd || netbsd
  5. // +build dragonfly freebsd netbsd
  6. package route
  7. func (w *wireFormat) parseInterfaceAnnounceMessage(_ RIBType, b []byte) (Message, error) {
  8. if len(b) < w.bodyOff {
  9. return nil, errMessageTooShort
  10. }
  11. l := int(nativeEndian.Uint16(b[:2]))
  12. if len(b) < l {
  13. return nil, errInvalidMessage
  14. }
  15. m := &InterfaceAnnounceMessage{
  16. Version: int(b[2]),
  17. Type: int(b[3]),
  18. Index: int(nativeEndian.Uint16(b[4:6])),
  19. What: int(nativeEndian.Uint16(b[22:24])),
  20. raw: b[:l],
  21. }
  22. for i := 0; i < 16; i++ {
  23. if b[6+i] != 0 {
  24. continue
  25. }
  26. m.Name = string(b[6 : 6+i])
  27. break
  28. }
  29. return m, nil
  30. }