We can determine the interface name ourselves
This commit is contained in:
parent
ab875491c0
commit
676bb91434
2
main.go
2
main.go
@ -90,7 +90,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
file := os.NewFile(uintptr(fd), "")
|
file := os.NewFile(uintptr(fd), "")
|
||||||
return CreateTUNFromFile(interfaceName, file)
|
return CreateTUNFromFile(file)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
10
tun_linux.go
10
tun_linux.go
@ -308,18 +308,22 @@ func (tun *NativeTun) Close() error {
|
|||||||
return tun.fd.Close()
|
return tun.fd.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateTUNFromFile(name string, fd *os.File) (TUNDevice, error) {
|
func CreateTUNFromFile(fd *os.File) (TUNDevice, error) {
|
||||||
device := &NativeTun{
|
device := &NativeTun{
|
||||||
fd: fd,
|
fd: fd,
|
||||||
name: name,
|
|
||||||
events: make(chan TUNEvent, 5),
|
events: make(chan TUNEvent, 5),
|
||||||
errors: make(chan error, 5),
|
errors: make(chan error, 5),
|
||||||
nopi: false,
|
nopi: false,
|
||||||
}
|
}
|
||||||
|
var err error
|
||||||
|
|
||||||
|
_, err = device.Name()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// start event listener
|
// start event listener
|
||||||
|
|
||||||
var err error
|
|
||||||
device.index, err = getIFIndex(device.name)
|
device.index, err = getIFIndex(device.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user