aboutsummaryrefslogtreecommitdiff
path: root/src/internal/syscall/windows
diff options
context:
space:
mode:
authorCarlos Castillo <cookieo9@gmail.com>2015-02-24 02:35:55 -0800
committerAlex Brainman <alex.brainman@gmail.com>2015-02-25 23:16:44 +0000
commit59e546633d5b41f69971bd9f019f5e54c600fa17 (patch)
tree00f41d4932194e365cf3afb9d97ecc4b5f26a853 /src/internal/syscall/windows
parentca0be6f849f227c409b06819d9b2d349a8045098 (diff)
downloadgo-59e546633d5b41f69971bd9f019f5e54c600fa17.tar.xz
os: Use GetComputerNameEx to get Hostname on win32
The existing Hostname function uses the GetComputerName system function in windows to determine the hostname. It has some downsides: - The name is limited to 15 characters. - The name returned is for NetBIOS, other OS's return a DNS name This change adds to the internal/syscall/windows package a GetComputerNameEx function, and related enum constants. They are used instead of the syscall.ComputerName function to implement os.Hostname on windows. Fixes #9982 Change-Id: Idc8782785eb1eea37e64022bd201699ce9c4b39c Reviewed-on: https://go-review.googlesource.com/5852 Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Run-TryBot: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Carlos Castillo <cookieo9@gmail.com> Reviewed-by: Yasuhiro MATSUMOTO <mattn.jp@gmail.com>
Diffstat (limited to 'src/internal/syscall/windows')
-rw-r--r--src/internal/syscall/windows/syscall_windows.go18
-rw-r--r--src/internal/syscall/windows/zsyscall_windows.go16
2 files changed, 31 insertions, 3 deletions
diff --git a/src/internal/syscall/windows/syscall_windows.go b/src/internal/syscall/windows/syscall_windows.go
index 2541a83440..49bfeea1f4 100644
--- a/src/internal/syscall/windows/syscall_windows.go
+++ b/src/internal/syscall/windows/syscall_windows.go
@@ -4,9 +4,7 @@
package windows
-import (
- "syscall"
-)
+import "syscall"
//go:generate go run ../../../syscall/mksyscall_windows.go -output zsyscall_windows.go syscall_windows.go
@@ -97,3 +95,17 @@ const (
)
//sys GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizeOfPointer *uint32) (errcode error) = iphlpapi.GetAdaptersAddresses
+
+//sys GetComputerNameEx(nameformat uint32, buf *uint16, n *uint32) (err error) = GetComputerNameExW
+
+const (
+ ComputerNameNetBIOS = 0
+ ComputerNameDnsHostname = 1
+ ComputerNameDnsDomain = 2
+ ComputerNameDnsFullyQualified = 3
+ ComputerNamePhysicalNetBIOS = 4
+ ComputerNamePhysicalDnsHostname = 5
+ ComputerNamePhysicalDnsDomain = 6
+ ComputerNamePhysicalDnsFullyQualified = 7
+ ComputerNameMax = 8
+)
diff --git a/src/internal/syscall/windows/zsyscall_windows.go b/src/internal/syscall/windows/zsyscall_windows.go
index 90e2034641..50c7c5165b 100644
--- a/src/internal/syscall/windows/zsyscall_windows.go
+++ b/src/internal/syscall/windows/zsyscall_windows.go
@@ -5,10 +5,14 @@ package windows
import "unsafe"
import "syscall"
+var _ unsafe.Pointer
+
var (
modiphlpapi = syscall.NewLazyDLL("iphlpapi.dll")
+ modkernel32 = syscall.NewLazyDLL("kernel32.dll")
procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses")
+ procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
)
func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizeOfPointer *uint32) (errcode error) {
@@ -18,3 +22,15 @@ func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapter
}
return
}
+
+func GetComputerNameEx(nameformat uint32, buf *uint16, n *uint32) (err error) {
+ r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nameformat), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)))
+ if r1 == 0 {
+ if e1 != 0 {
+ err = error(e1)
+ } else {
+ err = syscall.EINVAL
+ }
+ }
+ return
+}