예제 #1
0
        /// <summary>
        /// This function returns network interface stats for interfaces attached to the domain.
        /// The path parameter is the name of the network interface. Domains may have more than one network interface.
        /// To get stats for each you should make multiple calls to this function.
        /// Individual fields within the stats structure may be returned as -1,
        /// which indicates that the hypervisor does not support that particular statistic.
        /// </summary>
        /// <param name="dom">
        /// A <see cref="IntPtr"/>pointer to the domain object.
        /// </param>
        /// <param name="path">
        /// Path to the interface.
        /// </param>
        /// <param name="stats">
        /// A <see cref="DomainInterfaceStatsStruct"/>network interface stats (returned).
        /// </param>
        /// <returns>0 in case of success or -1 in case of failure.</returns>
        public static int InterfaceStats(IntPtr dom, string path, out DomainInterfaceStatsStruct stats)
        {
            DomainInterfaceStatsStruct statStruct = new DomainInterfaceStatsStruct();

            IntPtr statStructPtr = Marshal.AllocHGlobal(Marshal.SizeOf(statStruct));

            Marshal.StructureToPtr(statStruct, statStructPtr, true);
            int result = InterfaceStats(dom, path, statStructPtr, Marshal.SizeOf(statStruct));

            Marshal.PtrToStructure(statStructPtr, statStruct);
            stats = statStruct;
            Marshal.FreeHGlobal(statStructPtr);
            return(result);
        }
예제 #2
0
 /// <summary>
 /// This function returns network interface stats for interfaces attached to the domain.
 /// The path parameter is the name of the network interface. Domains may have more than one network interface.
 /// To get stats for each you should make multiple calls to this function.
 /// Individual fields within the stats structure may be returned as -1,
 /// which indicates that the hypervisor does not support that particular statistic.
 /// </summary>
 /// <param name="dom">
 /// A <see cref="IntPtr"/>pointer to the domain object.
 /// </param>
 /// <param name="path">
 /// Path to the interface.
 /// </param>
 /// <param name="stats">
 /// A <see cref="DomainInterfaceStatsStruct"/>network interface stats (returned).
 /// </param>
 /// <returns>0 in case of success or -1 in case of failure.</returns>
 public static int InterfaceStats(IntPtr dom, string path, out DomainInterfaceStatsStruct stats)
 {
     DomainInterfaceStatsStruct statStruct = new DomainInterfaceStatsStruct();
     IntPtr statStructPtr = Marshal.AllocHGlobal(Marshal.SizeOf(statStruct));
     Marshal.StructureToPtr(statStruct, statStructPtr, true);
     int result = InterfaceStats(dom, path, statStructPtr, Marshal.SizeOf(statStruct));
     Marshal.PtrToStructure(statStructPtr, statStruct);
     stats = statStruct;
     Marshal.FreeHGlobal(statStructPtr);
     return result;
 }