mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 12:27:37 +03:00
windnsapi: Fix incorrect error checking
This commit is contained in:
parent
96bef0733f
commit
afd8993773
4 changed files with 21 additions and 5 deletions
16
common/windnsapi/dnsapi_test.go
Normal file
16
common/windnsapi/dnsapi_test.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package windnsapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDNSAPI(t *testing.T) {
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
|
t.SkipNow()
|
||||||
|
}
|
||||||
|
t.Parallel()
|
||||||
|
require.NoError(t, FlushResolverCache())
|
||||||
|
}
|
|
@ -3,4 +3,4 @@ package windnsapi
|
||||||
//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output zsyscall_windows.go syscall_windows.go
|
//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output zsyscall_windows.go syscall_windows.go
|
||||||
|
|
||||||
// dnsapi.DnsFlushResolverCache is an undocumented function
|
// dnsapi.DnsFlushResolverCache is an undocumented function
|
||||||
//sys FlushResolverCache() (ret error) = dnsapi.DnsFlushResolverCache
|
//sys FlushResolverCache() (err error) = dnsapi.DnsFlushResolverCache
|
||||||
|
|
|
@ -43,10 +43,10 @@ var (
|
||||||
procDnsFlushResolverCache = moddnsapi.NewProc("DnsFlushResolverCache")
|
procDnsFlushResolverCache = moddnsapi.NewProc("DnsFlushResolverCache")
|
||||||
)
|
)
|
||||||
|
|
||||||
func FlushResolverCache() (ret error) {
|
func FlushResolverCache() (err error) {
|
||||||
r0, _, _ := syscall.Syscall(procDnsFlushResolverCache.Addr(), 0, 0, 0, 0)
|
r1, _, e1 := syscall.Syscall(procDnsFlushResolverCache.Addr(), 0, 0, 0, 0)
|
||||||
if r0 != 0 {
|
if r1 == 0 {
|
||||||
ret = syscall.Errno(r0)
|
err = errnoErr(e1)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue