diff --git a/common/windnsapi/dnsapi_windows.go b/common/windnsapi/dnsapi_windows.go new file mode 100644 index 0000000..1d5bc87 --- /dev/null +++ b/common/windnsapi/dnsapi_windows.go @@ -0,0 +1,21 @@ +package windnsapi + +import ( + "os" + "syscall" + + "golang.org/x/sys/windows" +) + +var ( + moddnsapi = windows.NewLazySystemDLL("dnsapi.dll") + procDnsFlushResolverCache = moddnsapi.NewProc("DnsFlushResolverCache") +) + +func FlushResolverCache() error { + r0, _, err := syscall.SyscallN(procDnsFlushResolverCache.Addr()) + if r0 == 0 { + return os.NewSyscallError("DnsFlushResolverCache", err) + } + return nil +} diff --git a/go.mod b/go.mod index 45d4d34..dae7b7a 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/sagernet/sing go 1.18 -require golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 +require golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec diff --git a/go.sum b/go.sum index 25341eb..25e1312 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAc5XyaeamM+0VHRd4lc= -golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI= +golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=