route_classic.go 818 B

12345678910111213141516171819202122232425262728293031
  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. // +build darwin dragonfly freebsd netbsd
  5. package route
  6. func (w *wireFormat) parseRouteMessage(typ RIBType, b []byte) (Message, error) {
  7. if len(b) < w.bodyOff {
  8. return nil, errMessageTooShort
  9. }
  10. l := int(nativeEndian.Uint16(b[:2]))
  11. if len(b) < l {
  12. return nil, errInvalidMessage
  13. }
  14. m := &RouteMessage{
  15. Version: int(b[2]),
  16. Type: int(b[3]),
  17. Flags: int(nativeEndian.Uint32(b[8:12])),
  18. Index: int(nativeEndian.Uint16(b[4:6])),
  19. extOff: w.extOff,
  20. raw: b[:l],
  21. }
  22. var err error
  23. m.Addrs, err = parseAddrs(uint(nativeEndian.Uint32(b[12:16])), parseKernelInetAddr, b[w.bodyOff:])
  24. if err != nil {
  25. return nil, err
  26. }
  27. return m, nil
  28. }