From d7f0c51ecece0e0781ebc253d19fd4537af7d1e0 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] =?UTF-8?q?=E4=BF=AE=E8=AE=A2=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxy/tun/route_windows.go | 2 +- proxy/tun/tun.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/proxy/tun/route_windows.go b/proxy/tun/route_windows.go index cb44c58..158b860 100644 --- a/proxy/tun/route_windows.go +++ b/proxy/tun/route_windows.go @@ -14,7 +14,7 @@ var rememberedRouterIP string func init() { autoRouteFunc = func(tunDevName, tunGateway, tunIP string, directList []string) { - params := fmt.Sprintf(`interface ip set address name="%s" source=static addr=%s mask=255.255.255.0 gateway=none`, tunDevName, tunIP) + params := fmt.Sprintf(`interface ip set address name="%s" source=static addr=%s mask=255.255.255.0 gateway=%s`, tunDevName, tunIP, tunGateway) _, err := exec.Command("netsh", strings.Split(params, " ")...).Output() if err != nil { if ce := utils.CanLogErr("auto route failed"); ce != nil { diff --git a/proxy/tun/tun.go b/proxy/tun/tun.go index 8807249..23f4ee8 100644 --- a/proxy/tun/tun.go +++ b/proxy/tun/tun.go @@ -166,14 +166,21 @@ func (s *Server) Stop() { func (s *Server) StartListen(tcpRequestChan chan<- netLayer.TCPRequestInfo, udpRequestChan chan<- netLayer.UDPRequestInfo) io.Closer { s.stopped = false //log.Println(s.devName, s.selfip, s.realIP, s.mask) - if s.devName == "" && runtime.GOOS == "darwin" { - s.devName = "utun5" + if s.devName == "" { + switch runtime.GOOS { + case "darwin": + s.devName = "utun5" + case "windows": + s.devName = "vs_wintun" + + } } tunDev, err := tun.Open(s.devName) if err != nil { if ce := utils.CanLogErr("tun open failed"); ce != nil { ce.Write(zap.Error(err)) } + s.stopped = true return nil }