private void GetNDISAPs() { // Retrieve a list of NDIS_802_11_BSSID_LIST // structures from the driver. We'll parse that // list and populate ourselves based on the data // that we find there. string name = m_adapter.Name; byte[] data = NDISUIO.QueryOID(NDIS_OID.BSSID_LIST, name); if (data != null) { // Figure out how many SSIDs there are. NDIS_802_11_BSSID_LIST rawlist = new NDIS_802_11_BSSID_LIST(data, false); for (int i = 0; i < rawlist.NumberOfItems; i++) { // Get the next raw item from the list. BSSID bssid = rawlist.Item(i); // Using the raw item, create a cooked // SSID item. AccessPoint ssid = new AccessPoint(bssid); // Add the new item to this. m_aps.Add(ssid); } } else { throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error(), "Unable to get BSSID List"); } }
/// <summary> /// Returns objects that describe the network interfaces on the local computer. /// </summary> /// <returns> /// A System.Net.NetworkInformation.NetworkInterface array that contains objects /// that describe the available network interfaces, or an empty array if no interfaces /// are detected. /// </returns> public unsafe static INetworkInterface[] GetAllNetworkInterfaces() { NetworkInterface[] interfaceList; uint size; // get buffer size requirement NativeMethods.GetInterfaceInfo(null, out size); byte[] ifTable = new byte[size]; // pin the table buffer fixed(byte *pifTable = ifTable) { byte *p = pifTable; /* table looks like this: * typedef struct _IP_INTERFACE_INFO { * LONG NumAdapters; * IP_ADAPTER_INDEX_MAP Adapter[1]; * } IP_INTERFACE_INFO, *PIP_INTERFACE_INFO; * * typedef struct _IP_ADAPTER_INDEX_MAP { * ULONG Index; * WCHAR Name [MAX_ADAPTER_NAME]; * } IP_ADAPTER_INDEX_MAP, *PIP_ADAPTER_INDEX_MAP; */ // get the table data NativeMethods.GetInterfaceInfo(pifTable, out size); // get interface count int interfaceCount = *p; interfaceList = new NetworkInterface[interfaceCount]; p += 4; // get each interface for (int i = 0; i < interfaceCount; i++) { // get interface index int index = (int)*((int *)p); p += 4; // get interface name byte[] nameBytes = new byte[256]; Marshal.Copy(new IntPtr(p), nameBytes, 0, nameBytes.Length); string name = Encoding.Unicode.GetString(nameBytes, 0, nameBytes.Length); int nullIndex = name.IndexOf('\0'); if (nullIndex > 0) { name = name.Substring(0, nullIndex); } p += 256; // check the wireless capabilities try { NDISUIO.QueryOID(NDIS_OID.WEP_STATUS, name); // didn't throw, so it's wireless - determinine if it's WZC compatible INTF_ENTRY entry; if (WZC.QueryAdapter(name, out entry) == NativeMethods.NO_ERROR) { // this is a WZC wireless adapter interfaceList[i] = new WirelessZeroConfigNetworkInterface(index, name); } else { // this is a non-WZC wireless adapter interfaceList[i] = new WirelessNetworkInterface(index, name); } entry.Dispose(); } catch { // if it's not wireless, it will throw and end up here interfaceList[i] = new NetworkInterface(index, name); } } } return(interfaceList); }