route_openbsd.go 762 B

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