Esempio n. 1
0
        private static DisconnectWrapper.ConnectionInfo[] getTcpTable()
        {
            IntPtr intPtr = IntPtr.Zero;
            bool   flag   = false;

            DisconnectWrapper.ConnectionInfo[] result;
            try
            {
                int cb = 0;
                DisconnectWrapper.GetTcpTable(IntPtr.Zero, ref cb, false);
                intPtr = Marshal.AllocCoTaskMem(cb);
                flag   = true;
                DisconnectWrapper.GetTcpTable(intPtr, ref cb, false);
                int    num     = Marshal.ReadInt32(intPtr);
                IntPtr intPtr2 = (IntPtr)((int)intPtr + 4);
                DisconnectWrapper.ConnectionInfo[] array = new DisconnectWrapper.ConnectionInfo[num];
                int num2 = Marshal.SizeOf(default(DisconnectWrapper.ConnectionInfo));
                for (int i = 0; i < num; i++)
                {
                    array[i] = (DisconnectWrapper.ConnectionInfo)Marshal.PtrToStructure(intPtr2, typeof(DisconnectWrapper.ConnectionInfo));
                    intPtr2  = (IntPtr)((int)intPtr2 + num2);
                }
                result = array;
            }
            catch (Exception ex)
            {
                throw new Exception(string.Concat(new string[]
                {
                    "getTcpTable failed! [",
                    ex.GetType().ToString(),
                    ",",
                    ex.Message,
                    "]"
                }));
            }
            finally
            {
                if (flag)
                {
                    Marshal.FreeCoTaskMem(intPtr);
                }
            }
            return(result);
        }
Esempio n. 2
0
 public static void CloseConnection(string connectionstring)
 {
     try
     {
         string[] array = connectionstring.Split(new char[]
         {
             '-'
         });
         if (array.Length != 4)
         {
             throw new Exception("Invalid connectionstring - use the one provided by Connections.");
         }
         string[] array2 = array[0].Split(new char[]
         {
             ':'
         });
         string[] array3 = array[1].Split(new char[]
         {
             ':'
         });
         string[] array4 = array2[0].Split(new char[]
         {
             '.'
         });
         string[] array5 = array3[0].Split(new char[]
         {
             '.'
         });
         DisconnectWrapper.ConnectionInfo connectionInfo = default(DisconnectWrapper.ConnectionInfo);
         connectionInfo.dwState = 12;
         byte[] value = new byte[]
         {
             byte.Parse(array4[0]),
             byte.Parse(array4[1]),
             byte.Parse(array4[2]),
             byte.Parse(array4[3])
         };
         byte[] value2 = new byte[]
         {
             byte.Parse(array5[0]),
             byte.Parse(array5[1]),
             byte.Parse(array5[2]),
             byte.Parse(array5[3])
         };
         connectionInfo.dwLocalAddr  = BitConverter.ToInt32(value, 0);
         connectionInfo.dwRemoteAddr = BitConverter.ToInt32(value2, 0);
         connectionInfo.dwLocalPort  = DisconnectWrapper.htons(int.Parse(array2[1]));
         connectionInfo.dwRemotePort = DisconnectWrapper.htons(int.Parse(array3[1]));
         IntPtr ptrToNewObject = DisconnectWrapper.GetPtrToNewObject(connectionInfo);
         int    num            = DisconnectWrapper.SetTcpEntry(ptrToNewObject);
         if (num == -1)
         {
             throw new Exception("Unsuccessful");
         }
         if (num == 65)
         {
             throw new Exception("User has no sufficient privilege to execute this API successfully");
         }
         if (num == 87)
         {
             throw new Exception("Specified port is not in state to be closed down");
         }
         if (num != 0)
         {
             throw new Exception("Unknown error (" + num + ")");
         }
     }
     catch
     {
     }
 }