]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
setupapi: Merge _SP_DEVINFO_LIST_DETAIL_DATA and DevInfoListDetailData
authorSimon Rozman <simon@rozman.si>
Thu, 7 Feb 2019 21:23:03 +0000 (22:23 +0100)
committerSimon Rozman <simon@rozman.si>
Thu, 7 Feb 2019 22:49:50 +0000 (23:49 +0100)
Signed-off-by: Simon Rozman <simon@rozman.si>
tun/wintun/setupapi/setupapi_windows.go
tun/wintun/setupapi/setupapi_windows_test.go
tun/wintun/setupapi/types_windows.go
tun/wintun/setupapi/zsetupapi_windows.go

index 7bbda42ea750e920508d591b7e444cd1f9787ce2..d195ba4a6a9042ce4c13232804cb7c685d4b60e6 100644 (file)
@@ -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.
index 16d2603f75e68532e21e73f5edd320087b794362..b8f4bc70603d56cbc29468dbe60242dc545ed648 100644 (file)
@@ -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) {
index 23bee25e2263e62e9012247b7b51e46d31c16f7c..a37fdec0659478b11836454ff3464d1b70273d88 100644 (file)
@@ -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
index 3e393b4cc9e6b716d28c5da1f8fc198aa023bebc..9292413159fda259d229713e41e650337cfcc974 100644 (file)
@@ -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 {