コード例 #1
0
ファイル: NetworkAdapter.cs プロジェクト: hatRiot/fireBwall
        static void UpdateAdapterList()
        {
            bool succeeded = false;
            while (!succeeded)
            {

                if (!isNdisFilterDriverOpen)
                {
                    OpenNDISDriver();
                }
                TCP_AdapterList adList = new TCP_AdapterList();
                Ndisapi.GetTcpipBoundAdaptersInfo(hNdisapi, ref adList);
                List<NetworkAdapter> tempList = new List<NetworkAdapter>();

                //Populate with current adapters
                List<NetworkAdapter> notFound = new List<NetworkAdapter>();
                for (int x = 0; x < currentAdapters.Count; x++)
                {
                    bool found = false;
                    for (int y = 0; y < adList.m_nAdapterCount; y++)
                    {
                        if (adList.m_nAdapterHandle[y] == currentAdapters[x].adapterHandle)
                        {
                            currentAdapters[x].UpdateNetworkInterface(Encoding.ASCII.GetString(adList.m_szAdapterNameList, y * 256, 256));
                            tempList.Add(currentAdapters[x]);
                            found = true;
                        }
                    }
                    if (!found)
                    {
                        notFound.Add(currentAdapters[x]);
                    }
                }

                //Deal with no longer existant adapters
                for (int x = 0; x < notFound.Count; x++)
                {
                    notFound[x].SetNoLongerAvailable();
                }

                //Adding any new adapters
                for (int x = 0; x < adList.m_nAdapterCount; x++)
                {
                    bool found = false;
                    for (int y = 0; y < currentAdapters.Count; y++)
                    {
                        if (adList.m_nAdapterHandle[x] == currentAdapters[y].adapterHandle)
                            found = true;
                    }
                    if (!found)
                    {
                        NetworkAdapter newAdapter = new NetworkAdapter(adList.m_nAdapterHandle[x], Encoding.ASCII.GetString(adList.m_szAdapterNameList, x * 256, 256));
                        if (newAdapter.InterfaceInformation != null)
                        {
                            tempList.Add(newAdapter);
                        }
                    }
                }

                currentAdapters = new List<NetworkAdapter>(tempList);
                succeeded = true;
            }
        }
コード例 #2
0
ファイル: NetworkAdapter.cs プロジェクト: hatRiot/fireBwall
        static void OpenNDISDriver()
        {
            if (hNdisapi != IntPtr.Zero)
            {
                LogCenter.Instance.Push("NetworkAdapter-static", "Bad state was found, attempting to open the NDIS Filter Driver while the IntPtr != IntPtr.Zero, continuing");
            }

            hNdisapi = Ndisapi.OpenFilterDriver(Ndisapi.NDISRD_DRIVER_NAME);
            TCP_AdapterList adList = new TCP_AdapterList();
            Ndisapi.GetTcpipBoundAdaptersInfo(hNdisapi, ref adList);
            if (adList.m_nAdapterCount == 0)
            {
                LogCenter.WriteErrorLog(new Exception("No adapters found on this driver interface"));
                return;
            }
            isNdisFilterDriverOpen = true;
        }
コード例 #3
0
 public static extern bool GetTcpipBoundAdaptersInfo(IntPtr hOpen, ref TCP_AdapterList Adapters);
コード例 #4
0
ファイル: NetworkAdapter.cs プロジェクト: hatRiot/fireBwall
        public static List<NetworkAdapter> GetNewAdapters()
        {
            if (!isNdisFilterDriverOpen)
            {
                OpenNDISDriver();
            }
            TCP_AdapterList adList = new TCP_AdapterList();
            Ndisapi.GetTcpipBoundAdaptersInfo(hNdisapi, ref adList);
            List<NetworkAdapter> tempList = new List<NetworkAdapter>();
            for (int x = 0; x < currentAdapters.Count; x++)
            {
                for (int y = 0; y < adList.m_nAdapterCount; y++)
                {
                    if (adList.m_nAdapterHandle[y] == currentAdapters[x].adapterHandle)
                    {
                        currentAdapters[x].UpdateNetworkInterface(Encoding.ASCII.GetString(adList.m_szAdapterNameList, y * 256, 256));
                    }
                }
            }
            for (int x = 0; x < adList.m_nAdapterCount; x++)
            {
                bool found = false;
                for (int y = 0; y < currentAdapters.Count; y++)
                {
                    if (adList.m_nAdapterHandle[x] == currentAdapters[y].adapterHandle)
                        found = true;
                }
                if (!found)
                {
                    NetworkAdapter newAdapter = new NetworkAdapter(adList.m_nAdapterHandle[x], Encoding.ASCII.GetString(adList.m_szAdapterNameList, x * 256, 256));
                    if (newAdapter.InterfaceInformation != null)
                    {
                        tempList.Add(newAdapter);
                        currentAdapters.Add(newAdapter);
                    }
                }
            }

            return tempList;
        }
コード例 #5
0
ファイル: ndisapi.cs プロジェクト: hatRiot/fireBwall
 public static extern bool GetTcpipBoundAdaptersInfo(IntPtr hOpen, ref TCP_AdapterList Adapters);