Files
golang.net/route/interface_classic.go
Mikio Hara 30be488e91 route: new package
This change introduces a package that provides the basic manipulation of
routing facilities on BSD variants.

Unlike the existing APIs in syscall package of standard library, the
package tries to provide operating system and its architecture agnostic
APIs. At present, the package supports any version of Darwin, any
version of DragonFly BSD, FreeBSD 7 through 11, NetBSD 6 and above, and
OpenBSD 5.6 and above.

Updates golang/go#14724.

Change-Id: Id964ea22dec491ddac3776e3a8c8c10f140f96ac
Reviewed-on: https://go-review.googlesource.com/22446
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-05-14 01:16:38 +00:00

67 lines
1.6 KiB
Go

// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build darwin dragonfly netbsd
package route
import "runtime"
func (w *wireFormat) parseInterfaceMessage(_ RIBType, b []byte) (Message, error) {
if len(b) < w.bodyOff {
return nil, errMessageTooShort
}
l := int(nativeEndian.Uint16(b[:2]))
if len(b) < l {
return nil, errInvalidMessage
}
attrs := uint(nativeEndian.Uint32(b[4:8]))
if attrs&sysRTA_IFP == 0 {
return nil, nil
}
m := &InterfaceMessage{
Version: int(b[2]),
Type: int(b[3]),
Addrs: make([]Addr, sysRTAX_MAX),
Flags: int(nativeEndian.Uint32(b[8:12])),
Index: int(nativeEndian.Uint16(b[12:14])),
extOff: w.extOff,
raw: b[:l],
}
a, err := parseLinkAddr(b[w.bodyOff:])
if err != nil {
return nil, err
}
m.Addrs[sysRTAX_IFP] = a
m.Name = a.(*LinkAddr).Name
return m, nil
}
func (w *wireFormat) parseInterfaceAddrMessage(_ RIBType, b []byte) (Message, error) {
if len(b) < w.bodyOff {
return nil, errMessageTooShort
}
l := int(nativeEndian.Uint16(b[:2]))
if len(b) < l {
return nil, errInvalidMessage
}
m := &InterfaceAddrMessage{
Version: int(b[2]),
Type: int(b[3]),
Flags: int(nativeEndian.Uint32(b[8:12])),
raw: b[:l],
}
if runtime.GOOS == "netbsd" {
m.Index = int(nativeEndian.Uint16(b[16:18]))
} else {
m.Index = int(nativeEndian.Uint16(b[12:14]))
}
var err error
m.Addrs, err = parseAddrs(uint(nativeEndian.Uint32(b[4:8])), parseKernelInetAddr, b[w.bodyOff:])
if err != nil {
return nil, err
}
return m, nil
}