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