github.com/liloew/wireguard-go@v0.0.0-20220224014633-9cd745e6f114/tun/operateonfd.go (about) 1 //go:build darwin || freebsd 2 3 /* SPDX-License-Identifier: MIT 4 * 5 * Copyright (C) 2017-2021 WireGuard LLC. All Rights Reserved. 6 */ 7 8 package tun 9 10 import ( 11 "fmt" 12 ) 13 14 func (tun *NativeTun) operateOnFd(fn func(fd uintptr)) { 15 sysconn, err := tun.tunFile.SyscallConn() 16 if err != nil { 17 tun.errors <- fmt.Errorf("unable to find sysconn for tunfile: %s", err.Error()) 18 return 19 } 20 err = sysconn.Control(fn) 21 if err != nil { 22 tun.errors <- fmt.Errorf("unable to control sysconn for tunfile: %s", err.Error()) 23 } 24 }