Revise InterfaceInfoList's Item() method

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2020-04-24 09:21:18 +02:00
parent 8438e80891
commit 906bb6bf8d
2 changed files with 18 additions and 5 deletions

View file

@ -66,8 +66,8 @@ func (iil *InterfaceInfoList) Item(idx uint32) *InterfaceInfo {
}
addr := uintptr(unsafe.Pointer(iil))
addr += unsafe.Sizeof(InterfaceInfoList{})
iiArray := (*[(1 << 21) - 1]InterfaceInfo)(unsafe.Pointer(addr))
return &(*iiArray)[idx]
addr += unsafe.Sizeof(InterfaceInfo{}) * uintptr(idx)
return (*InterfaceInfo)(unsafe.Pointer(addr))
}
// Close frees the memory.

View file

@ -7,10 +7,20 @@ package wlanapi
import (
"testing"
"unsafe"
"golang.org/x/sys/windows"
)
func TestStruct(t *testing.T) {
if unsafe.Sizeof(InterfaceInfo{}) != 532 {
t.Errorf("InterfaceInfo wrong size: %v", unsafe.Sizeof(InterfaceInfo{}))
}
if unsafe.Sizeof(InterfaceInfoList{}) != 8 {
t.Errorf("InterfaceInfoList wrong size: %v", unsafe.Sizeof(InterfaceInfoList{}))
}
}
func Test(t *testing.T) {
session, version, err := CreateClientSession(2)
if err != nil {
@ -29,13 +39,16 @@ func Test(t *testing.T) {
for i := uint32(0); i < ifaces.NumberOfItems; i++ {
ii := ifaces.Item(i)
t.Logf("Interface: %v, state: %v, GUID: %v",
ii.InterfaceDescription(),
ii.State,
ii.InterfaceGUID)
if ii.State == InterfaceStateNotReady {
continue
}
desc := ii.InterfaceDescription()
t.Logf("Interface: %v", desc)
err = session.SetProfileEAPXMLUserData(&ii.InterfaceGUID, "foobar", 0, "<foobar></foobar>")
if err == nil {
t.Errorf("SetProfileEAPXMLUserData error expected")