Debian Codegraph @

libgo/go/golang.org/x/net/nettest/nettest_windows.go

raw
1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package nettest
6
7 import "syscall"
8
9 func supportsRawSocket() bool {
10 // From http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548.aspx:
11 // Note: To use a socket of type SOCK_RAW requires administrative privileges.
12 // Users running Winsock applications that use raw sockets must be a member of
13 // the Administrators group on the local computer, otherwise raw socket calls
14 // will fail with an error code of WSAEACCES. On Windows Vista and later, access
15 // for raw sockets is enforced at socket creation. In earlier versions of Windows,
16 // access for raw sockets is enforced during other socket operations.
17 for _, af := range []int{syscall.AF_INET, syscall.AF_INET6} {
18 s, err := syscall.Socket(af, syscall.SOCK_RAW, 0)
19 if err != nil {
20 continue
21 }
22 syscall.Closesocket(s)
23 return true
24 }
25 return false
26 }