summaryrefslogtreecommitdiffhomepage
path: root/tun/tun_darwin.go
diff options
context:
space:
mode:
Diffstat (limited to 'tun/tun_darwin.go')
-rw-r--r--tun/tun_darwin.go35
1 files changed, 6 insertions, 29 deletions
diff --git a/tun/tun_darwin.go b/tun/tun_darwin.go
index 54021c5..7a06af5 100644
--- a/tun/tun_darwin.go
+++ b/tun/tun_darwin.go
@@ -20,16 +20,6 @@ import (
const utunControlName = "com.apple.net.utun_control"
-// sockaddr_ctl specifeid in /usr/include/sys/kern_control.h
-type sockaddrCtl struct {
- scLen uint8
- scFamily uint8
- ssSysaddr uint16
- scID uint32
- scUnit uint32
- scReserved [5]uint32
-}
-
type NativeTun struct {
name string
tunFile *os.File
@@ -38,8 +28,6 @@ type NativeTun struct {
routeSocket int
}
-var sockaddrCtlSize uintptr = 32
-
func retryInterfaceByIndex(index int) (iface *net.Interface, err error) {
for i := 0; i < 20; i++ {
iface, err = net.InterfaceByIndex(index)
@@ -134,25 +122,14 @@ func CreateTUN(name string, mtu int) (Device, error) {
return nil, fmt.Errorf("IoctlGetCtlInfo: %w", err)
}
- sc := sockaddrCtl{
- scLen: uint8(sockaddrCtlSize),
- scFamily: unix.AF_SYSTEM,
- ssSysaddr: 2,
- scID: ctlInfo.Id,
- scUnit: uint32(ifIndex) + 1,
+ sc := &unix.SockaddrCtl{
+ ID: ctlInfo.Id,
+ Unit: uint32(ifIndex) + 1,
}
- scPointer := unsafe.Pointer(&sc)
-
- _, _, errno = unix.RawSyscall(
- unix.SYS_CONNECT,
- uintptr(fd),
- uintptr(scPointer),
- uintptr(sockaddrCtlSize),
- )
-
- if errno != 0 {
- return nil, fmt.Errorf("SYS_CONNECT: %v", errno)
+ err = unix.Connect(fd, sc)
+ if err != nil {
+ return nil, err
}
err = syscall.SetNonblock(fd, true)