From 676bb9143461ae25304c414fb19595fef9c310db Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 19 Apr 2018 15:54:33 +0200 Subject: [PATCH] We can determine the interface name ourselves --- main.go | 2 +- tun_linux.go | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index b12bb09..7742eef 100644 --- a/main.go +++ b/main.go @@ -90,7 +90,7 @@ func main() { } file := os.NewFile(uintptr(fd), "") - return CreateTUNFromFile(interfaceName, file) + return CreateTUNFromFile(file) }() if err != nil { diff --git a/tun_linux.go b/tun_linux.go index 06b5af4..ac9824f 100644 --- a/tun_linux.go +++ b/tun_linux.go @@ -308,18 +308,22 @@ func (tun *NativeTun) Close() error { return tun.fd.Close() } -func CreateTUNFromFile(name string, fd *os.File) (TUNDevice, error) { +func CreateTUNFromFile(fd *os.File) (TUNDevice, error) { device := &NativeTun{ fd: fd, - name: name, events: make(chan TUNEvent, 5), errors: make(chan error, 5), nopi: false, } + var err error + + _, err = device.Name() + if err != nil { + return nil, err + } // start event listener - var err error device.index, err = getIFIndex(device.name) if err != nil { return nil, err