1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Net.Sockets; 6 7 namespace System.Net.NetworkInformation 8 { 9 /// IP statistics. 10 internal class SystemIPGlobalStatistics : IPGlobalStatistics 11 { 12 private readonly Interop.IpHlpApi.MibIpStats _stats = new Interop.IpHlpApi.MibIpStats(); 13 SystemIPGlobalStatistics()14 private SystemIPGlobalStatistics() { } 15 SystemIPGlobalStatistics(AddressFamily family)16 internal SystemIPGlobalStatistics(AddressFamily family) 17 { 18 uint result = Interop.IpHlpApi.GetIpStatisticsEx(out _stats, family); 19 20 if (result != Interop.IpHlpApi.ERROR_SUCCESS) 21 { 22 throw new NetworkInformationException((int)result); 23 } 24 } 25 26 public override bool ForwardingEnabled { get { return _stats.forwardingEnabled; } } 27 28 public override int DefaultTtl { get { return (int)_stats.defaultTtl; } } 29 30 public override long ReceivedPackets { get { return _stats.packetsReceived; } } 31 32 public override long ReceivedPacketsWithHeadersErrors { get { return _stats.receivedPacketsWithHeaderErrors; } } 33 34 public override long ReceivedPacketsWithAddressErrors { get { return _stats.receivedPacketsWithAddressErrors; } } 35 36 public override long ReceivedPacketsForwarded { get { return _stats.packetsForwarded; } } 37 38 public override long ReceivedPacketsWithUnknownProtocol { get { return _stats.receivedPacketsWithUnknownProtocols; } } 39 40 public override long ReceivedPacketsDiscarded { get { return _stats.receivedPacketsDiscarded; } } 41 42 public override long ReceivedPacketsDelivered { get { return _stats.receivedPacketsDelivered; } } 43 44 public override long OutputPacketRequests { get { return _stats.packetOutputRequests; } } 45 46 public override long OutputPacketRoutingDiscards { get { return _stats.outputPacketRoutingDiscards; } } 47 48 public override long OutputPacketsDiscarded { get { return _stats.outputPacketsDiscarded; } } 49 50 public override long OutputPacketsWithNoRoute { get { return _stats.outputPacketsWithNoRoute; } } 51 52 public override long PacketReassemblyTimeout { get { return _stats.packetReassemblyTimeout; } } 53 54 public override long PacketReassembliesRequired { get { return _stats.packetsReassemblyRequired; } } 55 56 public override long PacketsReassembled { get { return _stats.packetsReassembled; } } 57 58 public override long PacketReassemblyFailures { get { return _stats.packetsReassemblyFailed; } } 59 60 public override long PacketsFragmented { get { return _stats.packetsFragmented; } } 61 62 public override long PacketFragmentFailures { get { return _stats.packetsFragmentFailed; } } 63 64 public override int NumberOfInterfaces { get { return (int)_stats.interfaces; } } 65 66 public override int NumberOfIPAddresses { get { return (int)_stats.ipAddresses; } } 67 68 public override int NumberOfRoutes { get { return (int)_stats.routes; } } 69 } 70 } 71