public void ConstructorSetsProperties()
        {
            WirelessZeroConfigNetworkInterface wirelessZeroConfigNI = new WirelessZeroConfigNetworkInterface(0, "Config1");
            AccessPointCollection target = new AccessPointCollection(wirelessZeroConfigNI, false);

            Assert.AreEqual <WirelessZeroConfigNetworkInterface>(wirelessZeroConfigNI, target.AssociatedAdapter, "Constructor did not set AssociatedAdapter property correctly");
        }
예제 #2
0
        internal AccessPointCollection(WirelessZeroConfigNetworkInterface a)
        {
            if (a == null)
            {
                throw new ArgumentNullException();
            }

            m_adapter = a;

            this.RefreshList(true);
        }
예제 #3
0
        internal AccessPointCollection(WirelessZeroConfigNetworkInterface intf, bool nearbyOnly)
        {
            if (intf == null)
            {
                throw new ArgumentNullException();
            }

            m_adapter = intf;

            this.RefreshListPreferred(nearbyOnly);
        }
        public void ConstructorValidWirelessZeroConfigNetworkInterface()
        {
            WirelessZeroConfigNetworkInterface wirelessZeroConfigNI = new WirelessZeroConfigNetworkInterface(0, "Config1");

            AccessPointCollection target = null;

            Exception caughtException = null;

            try
            {
                target = new AccessPointCollection(wirelessZeroConfigNI);
            }
            catch (Exception ex)
            {
                caughtException = ex;
            }

            Assert.IsNull(caughtException, "Constructor threw exception. AccessPointCollection was not constructed successfully");
        }
        /// <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);
        }