From 6fd5c009ee63f080b8501f8ec71b92672bbfd0cf Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 17 Sep 2004 22:16:14 +0000 Subject: [PATCH] add NetInterfaceStat binding --- bindings/dotnet/src/Sigar.cs | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/bindings/dotnet/src/Sigar.cs b/bindings/dotnet/src/Sigar.cs index fa37d010..9911bd30 100644 --- a/bindings/dotnet/src/Sigar.cs +++ b/bindings/dotnet/src/Sigar.cs @@ -57,6 +57,10 @@ namespace Hyperic.Sigar { return Hyperic.Sigar.NetInterfaceConfig.NativeGet(this, name); } + public NetInterfaceStat NetInterfaceStat(string name) { + return Hyperic.Sigar.NetInterfaceStat.NativeGet(this, name); + } + ~Sigar() { sigar_close(this.sigar.Handle); } @@ -432,4 +436,47 @@ namespace Hyperic.Sigar { } } } + + [StructLayout(LayoutKind.Sequential)] + public struct NetInterfaceStat { + public readonly ulong RxPackets; + public readonly ulong RxBytes; + public readonly ulong RxErrors; + public readonly ulong RxDropped; + public readonly ulong RxOverruns; + public readonly ulong RxFrame; + public readonly ulong TxPackets; + public readonly ulong TxBytes; + public readonly ulong TxErrors; + public readonly ulong TxDropped; + public readonly ulong TxOverruns; + public readonly ulong TxCollisions; + public readonly ulong TxCarrier; + + [DllImport(Sigar.LIBSIGAR)] + private static extern int + sigar_net_interface_stat_get(IntPtr sigar, string name, + IntPtr ifstat); + + 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 new ApplicationException("net_interface_stat_get"); + } + + NetInterfaceStat ifstat = + (NetInterfaceStat)Marshal.PtrToStructure(ptr, type); + + Marshal.FreeHGlobal(ptr); + + return ifstat; + } + } }