stack_windows.go 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2015 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 (
  6. "fmt"
  7. "runtime"
  8. "syscall"
  9. )
  10. // SupportsRawIPSocket reports whether the platform supports raw IP
  11. // sockets.
  12. func SupportsRawIPSocket() (string, bool) {
  13. // From http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548.aspx:
  14. // Note: To use a socket of type SOCK_RAW requires administrative privileges.
  15. // Users running Winsock applications that use raw sockets must be a member of
  16. // the Administrators group on the local computer, otherwise raw socket calls
  17. // will fail with an error code of WSAEACCES. On Windows Vista and later, access
  18. // for raw sockets is enforced at socket creation. In earlier versions of Windows,
  19. // access for raw sockets is enforced during other socket operations.
  20. s, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_RAW, 0)
  21. if err == syscall.WSAEACCES {
  22. return fmt.Sprintf("no access to raw socket allowed on %s", runtime.GOOS), false
  23. }
  24. if err != nil {
  25. return err.Error(), false
  26. }
  27. syscall.Closesocket(s)
  28. return "", true
  29. }