From 0374c719ee1792624369a7786e43356ca09d74a2 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 17 Sep 2004 18:00:16 +0000 Subject: [PATCH] add NetInterfaceList binding --- bindings/dotnet/src/Sigar.cs | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/bindings/dotnet/src/Sigar.cs b/bindings/dotnet/src/Sigar.cs index b63c23f1..b7328051 100644 --- a/bindings/dotnet/src/Sigar.cs +++ b/bindings/dotnet/src/Sigar.cs @@ -48,6 +48,10 @@ namespace Hyperic.Sigar { return Hyperic.Sigar.FileSystemUsage.NativeGet(this, dirname); } + public String[] NetInterfaceList() { + return Hyperic.Sigar.NetInterfaceList.NativeGet(this); + } + ~Sigar() { sigar_close(this.sigar.Handle); } @@ -302,4 +306,49 @@ namespace Hyperic.Sigar { return fsusage; } } + + [StructLayout(LayoutKind.Sequential)] + internal struct NetInterfaceList { + private readonly uint number; + private readonly uint size; + private readonly IntPtr data; + + [DllImport(Sigar.LIBSIGAR)] + private static extern int sigar_net_interface_list_get(IntPtr sigar, + IntPtr iflist); + + [DllImport(Sigar.LIBSIGAR)] + private static extern int sigar_net_interface_list_destroy(IntPtr sigar, + IntPtr iflist); + + 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 new ApplicationException("sigar_net_interface_list_get"); + } + + NetInterfaceList ifPtr = + (NetInterfaceList)Marshal.PtrToStructure(ptr, type); + + String[] iflist = new String[ifPtr.number]; + + IntPtr iptr = ifPtr.data; + + for (int i=0; i