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 := uintptr(unsafe.Pointer(iil))
addr += unsafe.Sizeof(InterfaceInfoList{}) addr += unsafe.Sizeof(InterfaceInfoList{})
iiArray := (*[(1 << 21) - 1]InterfaceInfo)(unsafe.Pointer(addr)) addr += unsafe.Sizeof(InterfaceInfo{}) * uintptr(idx)
return &(*iiArray)[idx] return (*InterfaceInfo)(unsafe.Pointer(addr))
} }
// Close frees the memory. // Close frees the memory.

View file

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