mirror of
https://github.com/golang/net.git
synced 2026-03-31 10:27:08 +09:00
For golang/go#54035 Change-Id: I5163bb1d562f0c7f7de16995fcb42ece894d07bf Reviewed-on: https://go-review.googlesource.com/c/net/+/419180 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Meng Zhuo <mzh@golangcn.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
72 lines
1.7 KiB
Go
72 lines
1.7 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.
|
|
|
|
//go:build darwin || dragonfly || netbsd
|
|
// +build darwin dragonfly netbsd
|
|
|
|
package route
|
|
|
|
import (
|
|
"runtime"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
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&unix.RTA_IFP == 0 {
|
|
return nil, nil
|
|
}
|
|
m := &InterfaceMessage{
|
|
Version: int(b[2]),
|
|
Type: int(b[3]),
|
|
Addrs: make([]Addr, unix.RTAX_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[unix.RTAX_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
|
|
}
|