From b439ca2c6635ff9de79628b9e7120e57764fd66c Mon Sep 17 00:00:00 2001 From: e1732a364fed <75717694+e1732a364fed@users.noreply.github.com> Date: Sat, 1 Jan 2000 00:00:00 +0000 Subject: [PATCH] fdbased tun, close #227 --- netLayer/tun/tun.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/netLayer/tun/tun.go b/netLayer/tun/tun.go index 3a6a9c30..989a7865 100644 --- a/netLayer/tun/tun.go +++ b/netLayer/tun/tun.go @@ -19,7 +19,7 @@ import ( "io" "log" "net" - "runtime" + "strconv" "time" "github.com/e1732a364fed/v2ray_simple/netLayer" @@ -40,18 +40,18 @@ import ( "gvisor.dev/gvisor/pkg/waiter" ) -// 若name为空则会返回错误 +// 若name为空则会返回错误. 若name可转换为数字,则会将其解析为fd 号 func Open(name string) (device.Device, error) { if name == "" { return nil, errors.New("tun: dev name can't be empty") } - if runtime.GOOS == "android" { + _, err := strconv.Atoi(name) + if err == nil { return fdbased.Open(name, uint32(utils.MTU)) - - } else { - return tun.Open(name, uint32(utils.MTU)) } + + return tun.Open(name, uint32(utils.MTU)) } type StackCloser struct {