From 0cf1ed9e522b7dbb416f080a5c8003de9b702bf4 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 20 Nov 2018 21:29:04 +0000 Subject: [PATCH] unix: add IoctlSetPointerInt IoctlSetPointerInt is necessary for interacting with the PPP kernel driver, which wants it passed as a pointer to int, rather than the more conventional int cast as a pointer. We can technically do this already with IoctlSetInt(int(uintptr(unsafe.Pointer(&foo)))), but that's just masking the operation we're trying to execute in the first place, and relying on the internals of IoctlSetInt to do the right inverse transformation. Change-Id: I1e6a1dd6190c11f06c6f5393cd2cae453939878a GitHub-Last-Rev: a88f56073d04b02d9c076b112adaf99169a49513 GitHub-Pull-Request: golang/sys#25 Reviewed-on: https://go-review.googlesource.com/c/150321 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- unix/syscall_linux.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index 96ff70dc..466b2576 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -57,6 +57,15 @@ func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { // ioctl itself should not be exposed directly, but additional get/set // functions for specific types are permissible. +// IoctlSetPointerInt performs an ioctl operation which sets an +// integer value on fd, using the specified request number. The ioctl +// argument is called with a pointer to the integer value, rather than +// passing the integer value directly. +func IoctlSetPointerInt(fd int, req uint, value int) error { + v := int32(value) + return ioctl(fd, req, uintptr(unsafe.Pointer(&v))) +} + // IoctlSetInt performs an ioctl operation which sets an integer value // on fd, using the specified request number. func IoctlSetInt(fd int, req uint, value int) error {