From a18737bcce9e60a63acb108d304d8d08b01a1cd5 Mon Sep 17 00:00:00 2001 From: fumiama Date: Wed, 29 Dec 2021 22:00:44 +0800 Subject: [PATCH] fix nil adapter --- syscalls_windows.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/syscalls_windows.go b/syscalls_windows.go index 46c013e..fd76a39 100644 --- a/syscalls_windows.go +++ b/syscalls_windows.go @@ -336,16 +336,21 @@ func openDev(config Config) (ifce *Interface, err error) { return openTap(config) } // TUN + var ad *wintun.Adapter if config.InterfaceName == "" { - config.InterfaceName = "Wintun" + config.InterfaceName = "WinTun" } - ad, err := wintun.OpenAdapter(config.InterfaceName) + ad, err = wintun.OpenAdapter(config.InterfaceName) if err != nil { - return nil, err + ad, err = wintun.CreateAdapter(config.InterfaceName, "Wintun", nil) + } + + if err != nil { + return } s, err := ad.StartSession(65536) if err != nil { - return nil, err + return } return &Interface{ReadWriteCloser: &wintunRWC{s: s, ad: ad}, name: config.InterfaceName}, nil }