summaryrefslogtreecommitdiffhomepage
path: root/tun/wintun
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-02-07 22:23:03 +0100
committerSimon Rozman <simon@rozman.si>2019-02-07 23:49:50 +0100
commit05d25fd1b71aaad8f542999851d472d63b724ae2 (patch)
tree4d9d20b7e5ed80a154d8c522b4338e267c58de84 /tun/wintun
parent6d2729dcccc7d02a2578ee28580b351769868b03 (diff)
setupapi: Merge _SP_DEVINFO_LIST_DETAIL_DATA and DevInfoListDetailData
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'tun/wintun')
-rw-r--r--tun/wintun/setupapi/setupapi_windows.go13
-rw-r--r--tun/wintun/setupapi/setupapi_windows_test.go10
-rw-r--r--tun/wintun/setupapi/types_windows.go27
-rw-r--r--tun/wintun/setupapi/zsetupapi_windows.go2
4 files changed, 26 insertions, 26 deletions
diff --git a/tun/wintun/setupapi/setupapi_windows.go b/tun/wintun/setupapi/setupapi_windows.go
index 7bbda42..d195ba4 100644
--- a/tun/wintun/setupapi/setupapi_windows.go
+++ b/tun/wintun/setupapi/setupapi_windows.go
@@ -29,19 +29,14 @@ func SetupDiCreateDeviceInfoListEx(classGUID *windows.GUID, hwndParent uintptr,
return setupDiCreateDeviceInfoListEx(classGUID, hwndParent, machineNameUTF16, 0)
}
-//sys setupDiGetDeviceInfoListDetail(deviceInfoSet DevInfo, deviceInfoSetDetailData *_SP_DEVINFO_LIST_DETAIL_DATA) (err error) = setupapi.SetupDiGetDeviceInfoListDetailW
+//sys setupDiGetDeviceInfoListDetail(deviceInfoSet DevInfo, deviceInfoSetDetailData *DevInfoListDetailData) (err error) = setupapi.SetupDiGetDeviceInfoListDetailW
// SetupDiGetDeviceInfoListDetail function retrieves information associated with a device information set including the class GUID, remote computer handle, and remote computer name.
func SetupDiGetDeviceInfoListDetail(deviceInfoSet DevInfo) (deviceInfoSetDetailData *DevInfoListDetailData, err error) {
- var _data _SP_DEVINFO_LIST_DETAIL_DATA
- _data.Size = uint32(unsafe.Sizeof(_data))
-
- err = setupDiGetDeviceInfoListDetail(deviceInfoSet, &_data)
- if err != nil {
- return
- }
+ data := &DevInfoListDetailData{}
+ data.size = uint32(unsafe.Sizeof(*data))
- return _data.toGo(), nil
+ return data, setupDiGetDeviceInfoListDetail(deviceInfoSet, data)
}
// GetDeviceInfoListDetail method retrieves information associated with a device information set including the class GUID, remote computer handle, and remote computer name.
diff --git a/tun/wintun/setupapi/setupapi_windows_test.go b/tun/wintun/setupapi/setupapi_windows_test.go
index 16d2603..b8f4bc7 100644
--- a/tun/wintun/setupapi/setupapi_windows_test.go
+++ b/tun/wintun/setupapi/setupapi_windows_test.go
@@ -63,7 +63,7 @@ func TestSetupDiGetDeviceInfoListDetail(t *testing.T) {
t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine handle")
}
- if data.RemoteMachineName != "" {
+ if data.GetRemoteMachineName() != "" {
t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine name")
}
}
@@ -86,10 +86,16 @@ func TestSetupDiGetDeviceInfoListDetail(t *testing.T) {
t.Error("SetupDiGetDeviceInfoListDetail returned NULL remote machine handle")
}
- if data.RemoteMachineName != computerName {
+ if data.GetRemoteMachineName() != computerName {
t.Error("SetupDiGetDeviceInfoListDetail returned different remote machine name")
}
}
+
+ data = &DevInfoListDetailData{}
+ data.SetRemoteMachineName("foobar")
+ if data.GetRemoteMachineName() != "foobar" {
+ t.Error("DevInfoListDetailData.(Get|Set)RemoteMachineName() differ")
+ }
}
func TestSetupDiCreateDeviceInfo(t *testing.T) {
diff --git a/tun/wintun/setupapi/types_windows.go b/tun/wintun/setupapi/types_windows.go
index 23bee25..a37fdec 100644
--- a/tun/wintun/setupapi/types_windows.go
+++ b/tun/wintun/setupapi/types_windows.go
@@ -57,26 +57,25 @@ type DevInfoData struct {
_ uintptr
}
-type _SP_DEVINFO_LIST_DETAIL_DATA struct {
- Size uint32
+// DevInfoListDetailData is a structure for detailed information on a device information set (used for SetupDiGetDeviceInfoListDetail which supercedes the functionality of SetupDiGetDeviceInfoListClass).
+type DevInfoListDetailData struct {
+ size uint32
ClassGUID windows.GUID
RemoteMachineHandle windows.Handle
- RemoteMachineName [SP_MAX_MACHINENAME_LENGTH]uint16
+ remoteMachineName [SP_MAX_MACHINENAME_LENGTH]uint16
}
-func (_data *_SP_DEVINFO_LIST_DETAIL_DATA) toGo() *DevInfoListDetailData {
- return &DevInfoListDetailData{
- ClassGUID: _data.ClassGUID,
- RemoteMachineHandle: _data.RemoteMachineHandle,
- RemoteMachineName: windows.UTF16ToString(_data.RemoteMachineName[:]),
- }
+func (data *DevInfoListDetailData) GetRemoteMachineName() string {
+ return windows.UTF16ToString(data.remoteMachineName[:])
}
-// DevInfoListDetailData is a structure for detailed information on a device information set (used for SetupDiGetDeviceInfoListDetail which supercedes the functionality of SetupDiGetDeviceInfoListClass).
-type DevInfoListDetailData struct {
- ClassGUID windows.GUID
- RemoteMachineHandle windows.Handle
- RemoteMachineName string
+func (data *DevInfoListDetailData) SetRemoteMachineName(remoteMachineName string) error {
+ str, err := syscall.UTF16FromString(remoteMachineName)
+ if err != nil {
+ return err
+ }
+ copy(data.remoteMachineName[:], str)
+ return nil
}
// DI_FUNCTION is function type for device installer
diff --git a/tun/wintun/setupapi/zsetupapi_windows.go b/tun/wintun/setupapi/zsetupapi_windows.go
index 3e393b4..9292413 100644
--- a/tun/wintun/setupapi/zsetupapi_windows.go
+++ b/tun/wintun/setupapi/zsetupapi_windows.go
@@ -79,7 +79,7 @@ func setupDiCreateDeviceInfoListEx(classGUID *windows.GUID, hwndParent uintptr,
return
}
-func setupDiGetDeviceInfoListDetail(deviceInfoSet DevInfo, deviceInfoSetDetailData *_SP_DEVINFO_LIST_DETAIL_DATA) (err error) {
+func setupDiGetDeviceInfoListDetail(deviceInfoSet DevInfo, deviceInfoSetDetailData *DevInfoListDetailData) (err error) {
r1, _, e1 := syscall.Syscall(procSetupDiGetDeviceInfoListDetailW.Addr(), 2, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoSetDetailData)), 0)
if r1 == 0 {
if e1 != 0 {