Example #1
0
        internal static NetInterfaceStat NativeGet(Hyperic.Sigar.Sigar sigar, string name)
        {
            Type   type  = typeof(NetInterfaceStat);
            IntPtr num   = Marshal.AllocHGlobal(Marshal.SizeOf(type));
            int    errno = NetInterfaceStat.sigar_net_interface_stat_get(sigar.sigar.Handle, name, num);

            if (errno != 0)
            {
                Marshal.FreeHGlobal(num);
                throw Hyperic.Sigar.Sigar.FindException(sigar, errno);
            }
            NetInterfaceStat structure = (NetInterfaceStat)Marshal.PtrToStructure(num, type);

            Marshal.FreeHGlobal(num);
            return(structure);
        }
Example #2
0
        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);
        }