Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <I_OWNER_MODULE> GetAllUDP6Connections()
        {
            IntPtr buffTable = IntPtr.Zero;

            try
            {
                int buffSize = 0;
                GetExtendedUdpTable(IntPtr.Zero, ref buffSize, true, AF_INET.IP6, UDP_TABLE_CLASS.UDP_TABLE_OWNER_MODULE, 0);

                buffTable = Marshal.AllocHGlobal(buffSize);

                uint ret = GetExtendedUdpTable(buffTable, ref buffSize, true, AF_INET.IP6, UDP_TABLE_CLASS.UDP_TABLE_OWNER_MODULE, 0);
                if (ret == 0)
                {
                    MIB_UDP6TABLE_OWNER_MODULE tab = (MIB_UDP6TABLE_OWNER_MODULE)Marshal.PtrToStructure(buffTable, typeof(MIB_UDP6TABLE_OWNER_MODULE));
                    IntPtr rowPtr = (IntPtr)((long)buffTable + (long)Marshal.OffsetOf(typeof(MIB_UDP6TABLE_OWNER_MODULE), "FirstEntry"));

                    MIB_UDP6ROW_OWNER_MODULE current;
                    for (int i = 0; i < tab.NumEntries; i++)
                    {
                        current = (MIB_UDP6ROW_OWNER_MODULE)Marshal.PtrToStructure(rowPtr, typeof(MIB_UDP6ROW_OWNER_MODULE));
                        rowPtr  = (IntPtr)((long)rowPtr + (long)Marshal.SizeOf(current));

                        yield return(current);
                    }
                }
                else
                {
                    throw new Win32Exception((int)ret);
                }
            }
            finally
            {
                if (buffTable != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(buffTable);
                }
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <IConnectionOwnerInfo> GetAllUDP6Connections()
        {
            IntPtr buffTable = IntPtr.Zero;

            try
            {
                var buffSize = 0;
                _ = UDPHelper.NativeMethods.GetExtendedUdpTable(IntPtr.Zero, ref buffSize, true, AF_INET.IP6, UDP_TABLE_CLASS.UDP_TABLE_OWNER_MODULE, 0);

                buffTable = Marshal.AllocHGlobal(buffSize);

                uint ret = UDPHelper.NativeMethods.GetExtendedUdpTable(buffTable, ref buffSize, true, AF_INET.IP6, UDP_TABLE_CLASS.UDP_TABLE_OWNER_MODULE, 0);
                if (ret == 0)
                {
                    MIB_UDP6TABLE_OWNER_MODULE tab = Marshal.PtrToStructure <MIB_UDP6TABLE_OWNER_MODULE>(buffTable);
                    var rowPtr = (IntPtr)((long)buffTable + (long)Marshal.OffsetOf <MIB_UDP6TABLE_OWNER_MODULE>(nameof(MIB_UDP6TABLE_OWNER_MODULE.FirstEntry)));

                    MIB_UDP6ROW_OWNER_MODULE current;
                    for (var i = 0; i < tab.NumEntries; i++)
                    {
                        current = Marshal.PtrToStructure <MIB_UDP6ROW_OWNER_MODULE>(rowPtr);
                        rowPtr  = (IntPtr)((long)rowPtr + Marshal.SizeOf(current));

                        yield return(current);
                    }
                }
                else
                {
                    throw new Win32Exception((int)ret);
                }
            }
            finally
            {
                if (buffTable != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(buffTable);
                }
            }
        }