internal static string[] NativeGet(Sigar sigar) { System.Type typeFromHandle = typeof(NetInterfaceList); System.IntPtr intPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(typeFromHandle)); int num = NetInterfaceList.sigar_net_interface_list_get(sigar.sigar.Handle, intPtr); if (num != 0) { System.Runtime.InteropServices.Marshal.FreeHGlobal(intPtr); throw Sigar.FindException(sigar, num); } NetInterfaceList netInterfaceList = (NetInterfaceList)System.Runtime.InteropServices.Marshal.PtrToStructure(intPtr, typeFromHandle); string[] array = new string[netInterfaceList.number]; System.IntPtr ptr = netInterfaceList.data; int num2 = 0; while ((long)num2 < (long)((ulong)netInterfaceList.number)) { System.IntPtr ptr2 = System.Runtime.InteropServices.Marshal.ReadIntPtr(ptr, num2 * System.IntPtr.Size); array[num2] = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ptr2); num2++; } NetInterfaceList.sigar_net_interface_list_destroy(sigar.sigar.Handle, intPtr); System.Runtime.InteropServices.Marshal.FreeHGlobal(intPtr); return(array); }
internal static Who[] NativeGet(Sigar sigar) { System.Type typeFromHandle = typeof(WhoList); System.IntPtr intPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(typeFromHandle)); int num = WhoList.sigar_who_list_get(sigar.sigar.Handle, intPtr); if (num != 0) { System.Runtime.InteropServices.Marshal.FreeHGlobal(intPtr); throw Sigar.FindException(sigar, num); } WhoList whoList = (WhoList)System.Runtime.InteropServices.Marshal.PtrToStructure(intPtr, typeFromHandle); Who[] array = new Who[whoList.Number]; System.IntPtr ptr = whoList.data; int num2 = System.Runtime.InteropServices.Marshal.SizeOf(array[0]); int num3 = 0; while ((long)num3 < (long)((ulong)whoList.Number)) { array[num3] = (Who)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr, typeof(Who)); ptr = Sigar.incrementIntPtr(ptr, num2); num3++; } WhoList.sigar_who_list_destroy(sigar.sigar.Handle, intPtr); System.Runtime.InteropServices.Marshal.FreeHGlobal(intPtr); return(array); }
internal static String[] NativeGet(Sigar sigar) { Type type = typeof(NetInterfaceList); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type)); int status = sigar_net_interface_list_get(sigar.sigar.Handle, ptr); if (status != Sigar.OK) { Marshal.FreeHGlobal(ptr); throw Sigar.FindException(sigar, status); } NetInterfaceList ifPtr = (NetInterfaceList)Marshal.PtrToStructure(ptr, type); String[] iflist = new String[ifPtr.number]; IntPtr iptr = ifPtr.data; for (int i = 0; i < ifPtr.number; i++) { IntPtr str = Marshal.ReadIntPtr(iptr, i * IntPtr.Size); iflist[i] = Marshal.PtrToStringAnsi(str); } sigar_net_interface_list_destroy(sigar.sigar.Handle, ptr); Marshal.FreeHGlobal(ptr); return(iflist); }
internal static Cpu NativeGet(Sigar sigar) { Type type = typeof(Cpu); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type)); int status = sigar_cpu_get(sigar.sigar.Handle, ptr); if (status != Sigar.OK) { Marshal.FreeHGlobal(ptr); throw Sigar.FindException(sigar, status); } Cpu cpu = (Cpu)Marshal.PtrToStructure(ptr, type); Marshal.FreeHGlobal(ptr); return(cpu); }
internal static Mem NativeGet(Sigar sigar) { Type type = typeof(Mem); //sigar_mem_t *ptr = malloc(sizeof(*ptr)) IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type)); int status = sigar_mem_get(sigar.sigar.Handle, ptr); if (status != Sigar.OK) { Marshal.FreeHGlobal(ptr); throw Sigar.FindException(sigar, status); } //memcpy(ptr, this, sizeof(this)) Mem mem = (Mem)Marshal.PtrToStructure(ptr, type); Marshal.FreeHGlobal(ptr); return(mem); }
internal static NetInterfaceStat NativeGet(Sigar sigar, string name) { Type type = typeof(NetInterfaceStat); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type)); int status = sigar_net_interface_stat_get(sigar.sigar.Handle, name, ptr); if (status != Sigar.OK) { Marshal.FreeHGlobal(ptr); throw Sigar.FindException(sigar, status); } NetInterfaceStat ifstat = (NetInterfaceStat)Marshal.PtrToStructure(ptr, type); Marshal.FreeHGlobal(ptr); return(ifstat); }
internal static FileSystemUsage NativeGet(Sigar sigar, string dirname) { Type type = typeof(FileSystemUsage); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type)); int status = sigar_file_system_usage_get(sigar.sigar.Handle, dirname, ptr); if (status != Sigar.OK) { Marshal.FreeHGlobal(ptr); throw Sigar.FindException(sigar, status); } FileSystemUsage fsusage = (FileSystemUsage)Marshal.PtrToStructure(ptr, type); Marshal.FreeHGlobal(ptr); return(fsusage); }
internal static FileSystem[] NativeGet(Sigar sigar) { Type type = typeof(FileSystemList); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type)); int status = sigar_file_system_list_get(sigar.sigar.Handle, ptr); if (status != Sigar.OK) { Marshal.FreeHGlobal(ptr); throw Sigar.FindException(sigar, status); } FileSystemList fsPtr = (FileSystemList)Marshal.PtrToStructure(ptr, type); FileSystem[] fs = new FileSystem[fsPtr.Number]; IntPtr fptr = fsPtr.data; int size = Marshal.SizeOf(fs[0]); for (int i = 0; i < fsPtr.Number; i++) { fs[i] = (FileSystem)Marshal.PtrToStructure(fptr, typeof(FileSystem)); //fptr += sizeof(sigar_fs_t); fptr = Sigar.incrementIntPtr(fptr, size); } sigar_file_system_list_destroy(sigar.sigar.Handle, ptr); Marshal.FreeHGlobal(ptr); return(fs); }
internal static CpuInfo[] NativeGet(Sigar sigar) { Type type = typeof(CpuInfoList); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(type)); int status = sigar_cpu_info_list_get(sigar.sigar.Handle, ptr); if (status != Sigar.OK) { Marshal.FreeHGlobal(ptr); throw Sigar.FindException(sigar, status); } CpuInfoList infosPtr = (CpuInfoList)Marshal.PtrToStructure(ptr, type); CpuInfo[] infos = new CpuInfo[infosPtr.Number]; IntPtr eptr = infosPtr.data; int size = Marshal.SizeOf(infos[0]); for (int i = 0; i < infosPtr.Number; i++) { infos[i] = (CpuInfo)Marshal.PtrToStructure(eptr, typeof(CpuInfo)); //eptr += sizeof(sigar_cpu_info_t); eptr = Sigar.incrementIntPtr(eptr, size); } sigar_cpu_info_list_destroy(sigar.sigar.Handle, ptr); Marshal.FreeHGlobal(ptr); return(infos); }