nettest_windows.go 989 B

1234567891011121314151617181920212223242526
  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. package nettest
  5. import "syscall"
  6. func supportsRawSocket() bool {
  7. // From http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548.aspx:
  8. // Note: To use a socket of type SOCK_RAW requires administrative privileges.
  9. // Users running Winsock applications that use raw sockets must be a member of
  10. // the Administrators group on the local computer, otherwise raw socket calls
  11. // will fail with an error code of WSAEACCES. On Windows Vista and later, access
  12. // for raw sockets is enforced at socket creation. In earlier versions of Windows,
  13. // access for raw sockets is enforced during other socket operations.
  14. for _, af := range []int{syscall.AF_INET, syscall.AF_INET6} {
  15. s, err := syscall.Socket(af, syscall.SOCK_RAW, 0)
  16. if err != nil {
  17. continue
  18. }
  19. syscall.Closesocket(s)
  20. return true
  21. }
  22. return false
  23. }