| 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 |
|
| 5 |
package routebsd |
| 6 |
|
| 7 |
import "syscall" |
| 8 |
|
| 9 |
// MTU returns the interface MTU. |
| 10 |
func (m *InterfaceMessage) MTU() int { |
| 11 |
return int(nativeEndian.Uint32(m.raw[m.extOff+8 : m.extOff+12])) |
| 12 |
} |
| 13 |
|
| 14 |
// sizeofIfMsghdr2 is copied from x/sys/unix. |
| 15 |
const sizeofIfMsghdr2 = 0xa0 |
| 16 |
|
| 17 |
func probeRoutingStack() (int, map[int]*wireFormat) { |
| 18 |
ifm := &wireFormat{extOff: 16, bodyOff: syscall.SizeofIfMsghdr} |
| 19 |
ifm.parse = ifm.parseInterfaceMessage |
| 20 |
ifm2 := &wireFormat{extOff: 32, bodyOff: sizeofIfMsghdr2} |
| 21 |
ifm2.parse = ifm2.parseInterfaceMessage |
| 22 |
ifam := &wireFormat{extOff: syscall.SizeofIfaMsghdr, bodyOff: syscall.SizeofIfaMsghdr} |
| 23 |
ifam.parse = ifam.parseInterfaceAddrMessage |
| 24 |
ifmam := &wireFormat{extOff: syscall.SizeofIfmaMsghdr, bodyOff: syscall.SizeofIfmaMsghdr} |
| 25 |
ifmam.parse = ifmam.parseInterfaceMulticastAddrMessage |
| 26 |
ifmam2 := &wireFormat{extOff: syscall.SizeofIfmaMsghdr2, bodyOff: syscall.SizeofIfmaMsghdr2} |
| 27 |
ifmam2.parse = ifmam2.parseInterfaceMulticastAddrMessage |
| 28 |
// Darwin kernels require 32-bit aligned access to routing facilities. |
| 29 |
return 4, map[int]*wireFormat{ |
| 30 |
syscall.RTM_NEWADDR: ifam, |
| 31 |
syscall.RTM_DELADDR: ifam, |
| 32 |
syscall.RTM_IFINFO: ifm, |
| 33 |
syscall.RTM_NEWMADDR: ifmam, |
| 34 |
syscall.RTM_DELMADDR: ifmam, |
| 35 |
syscall.RTM_IFINFO2: ifm2, |
| 36 |
syscall.RTM_NEWMADDR2: ifmam2, |
| 37 |
} |
| 38 |
} |