From 119d4633e4d1df8fe59217f0e60ce5a83f6b3958 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 23 Oct 2020 17:34:06 +0200 Subject: [PATCH] unix: add Ioctl{Get,Set}IfreqMTU on darwin For golang/go#41868 Change-Id: I9fb8f5eee933488e4c63aaa757059b8cea4d9629 Reviewed-on: https://go-review.googlesource.com/c/sys/+/264637 Trust: Tobias Klauser Run-TryBot: Tobias Klauser Reviewed-by: Matt Layher TryBot-Result: Go Bot --- unix/syscall_darwin.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/unix/syscall_darwin.go b/unix/syscall_darwin.go index 5b0e831f..7fc58d6d 100644 --- a/unix/syscall_darwin.go +++ b/unix/syscall_darwin.go @@ -264,6 +264,29 @@ func IoctlCtlInfo(fd int, ctlInfo *CtlInfo) error { return err } +// IfreqMTU is struct ifreq used to get or set a network device's MTU. +type IfreqMTU struct { + Name [IFNAMSIZ]byte + MTU int32 +} + +// IoctlGetIfreqMTU performs the SIOCGIFMTU ioctl operation on fd to get the MTU +// of the network device specified by ifname. +func IoctlGetIfreqMTU(fd int, ifname string) (*IfreqMTU, error) { + var ifreq IfreqMTU + copy(ifreq.Name[:], ifname) + err := ioctl(fd, SIOCGIFMTU, uintptr(unsafe.Pointer(&ifreq))) + return &ifreq, err +} + +// IoctlSetIfreqMTU performs the SIOCSIFMTU ioctl operation on fd to set the MTU +// of the network device specified by ifreq.Name. +func IoctlSetIfreqMTU(fd int, ifreq *IfreqMTU) error { + err := ioctl(fd, SIOCSIFMTU, uintptr(unsafe.Pointer(ifreq))) + runtime.KeepAlive(ifreq) + return err +} + //sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS_SYSCTL func Uname(uname *Utsname) error {