tun: use sysconn instead of .Fd with Go 1.12

This commit is contained in:
Jason A. Donenfeld
2019-02-27 01:06:43 +01:00
parent 66524c1f7e
commit ab0f442daf
6 changed files with 80 additions and 55 deletions

View File

@@ -5,7 +5,10 @@
package tun
import "os"
import (
"fmt"
"os"
)
type TUNEvent int
@@ -24,3 +27,15 @@ type TUNDevice interface {
Events() chan TUNEvent // returns a constant channel of events related to the device
Close() error // stops the device and closes the event channel
}
func (tun *nativeTun) operateOnFd(fn func(fd uintptr)) {
sysconn, err := tun.tunFile.SyscallConn()
if err != nil {
tun.errors <- fmt.Errorf("unable to find sysconn for tunfile: %s", err.Error())
return
}
err = sysconn.Control(fn)
if err != nil {
tun.errors <- fmt.Errorf("unable to control sysconn for tunfile: %s", err.Error())
}
}