繁体   English   中英

在Windows 10上使用C#编写WlanGetNetworkBssList

[英]WlanGetNetworkBssList with c# on windows 10

我试图在Windows 10下从C#桌面应用程序互操作WlanGetNetworkBssList。在正确检索WLAN_BSS_LIST时遇到一些问题。 不知道问题出在哪里,我得到的清单是错误的。 第一项似乎是正确的,但其他所有项都没有。 我希望有一个人可以帮助我。

这些是即时通讯使用的结构。 我认为问题是结构定义错误。

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct WLAN_BSS_LIST
{
    internal Int32 dwTotalSize;
    internal Int32 dwNumberOfItems;
    internal WLAN_BSS_ENTRY[] wlanBssEntries;
    internal WLAN_BSS_LIST(IntPtr ppWlanBssList)
    {
        dwTotalSize = (Int32)Marshal.ReadInt32(ppWlanBssList);
        dwNumberOfItems = (Int32)Marshal.ReadInt32(ppWlanBssList + 4);
        wlanBssEntries = new WLAN_BSS_ENTRY[dwNumberOfItems];
        int WLAN_BSS_ENTRY_SIZE = Marshal.SizeOf(typeof(WLAN_BSS_ENTRY));
        for (int i = 0; i < dwNumberOfItems; i++)
        {
            IntPtr pItemList = new IntPtr(ppWlanBssList.ToInt32() + i * Marshal.SizeOf(typeof(WLAN_BSS_ENTRY)) + 8);
            wlanBssEntries[i] = (WLAN_BSS_ENTRY)Marshal.PtrToStructure(pItemList, typeof(WLAN_BSS_ENTRY));
        }
    }
}
public struct WLAN_BSS_ENTRY
{
    public DOT11_SSID dot11Ssid;
    public ulong uPhyId;
    public DOT11_MAC_ADDRESS dot11Bssid;
    public DOT11_BSS_TYPE dot11BssType;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
    public DOT11_PHY_TYPE[] dot11BssPhyType;
    public long lRssi;
    public ulong uLinkQuality;
    public bool bInRegDomain;
    public ushort usBeaconPeriod;
    public ulong ullTimestamp;
    public ulong ullHostTimestamp;
    public ushort usCapabilityInformation;
    public ulong ulChCenterFrequency;
    public WLAN_RATE_SET wlanRateSet;
    public ulong ulIeOffset;
    public ulong ulIeSize;
}
public struct DOT11_SSID
{
    public uint uSSIDLength;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
    public string ucSSID;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct DOT11_MAC_ADDRESS
{
    public byte one;
    public byte two;
    public byte three;
    public byte four;
    public byte five;
    public byte six;
}
public enum DOT11_BSS_TYPE
{
    dot11_BSS_type_infrastructure = 1,
    dot11_BSS_type_independent = 2,
    dot11_BSS_type_any = 3,
}
public enum DOT11_PHY_TYPE
{
    dot11_phy_type_unknown,
    dot11_phy_type_any,
    dot11_phy_type_fhss,
    dot11_phy_type_dsss,
    dot11_phy_type_irbaseband,
    dot11_phy_type_ofdm,
    dot11_phy_type_hrdsss,
    dot11_phy_type_erp,
    dot11_phy_type_ht,
    dot11_phy_type_IHV_start,
    dot11_phy_type_IHV_end,
}
public struct WLAN_RATE_SET
{
    public ulong uRateSetLength;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 126)]
    public ushort[] usRateSet;
}

快速解决方案是将您的代码更改为使用Ilya Konstantinov的Managed Wifi API库。 它已获得MIT许可。 我有一个使用SafeHandles进行所有资源管理的叉子,但是原始代码是可靠的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM