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.
5 // +build darwin dragonfly freebsd netbsd openbsd
9 // A Message represents a routing message.
10 type Message interface {
11 // Sys returns operating system-specific information.
15 // A Sys reprensents operating system-specific information.
17 // SysType returns a type of operating system-specific
22 // A SysType represents a type of operating system-specific
27 SysMetrics SysType = iota
31 // ParseRIB parses b as a routing information base and returns a list
32 // of routing messages.
33 func ParseRIB(typ RIBType, b []byte) ([]Message, error) {
35 return nil, errUnsupportedMessage
41 l := int(nativeEndian.Uint16(b[:2]))
43 return nil, errInvalidMessage
46 return nil, errMessageTooShort
48 if b[2] != sysRTM_VERSION {
52 if w, ok := wireFormats[int(b[3])]; !ok {
55 m, err := w.parse(typ, b)
62 msgs = append(msgs, m)
67 // We failed to parse any of the messages - version mismatch?
68 if nmsgs != len(msgs)+nskips {
69 return nil, errMessageMismatch