2007-08-27 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Mon, 27 Aug 2007 04:42:29 +0000 (04:42 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Mon, 27 Aug 2007 04:42:29 +0000 (04:42 -0000)
* IPGlobalProperties.cs, TcpConnectionInformation.cs,
  TcpStatistics.cs, IPGlobalStatistics.cs, IcmpV4Statistics.cs,
  IcmpV6Statistics.cs, UdpStatistics.cs :
  initial implementation of IPGlobalProperties and its children
  for Win32 API, mostly done. Non-Windows implementation should
  follow.

svn path=/trunk/mcs/; revision=84864

mcs/class/System/System.Net.NetworkInformation/ChangeLog
mcs/class/System/System.Net.NetworkInformation/IPGlobalProperties.cs
mcs/class/System/System.Net.NetworkInformation/IPGlobalStatistics.cs
mcs/class/System/System.Net.NetworkInformation/IcmpV4Statistics.cs
mcs/class/System/System.Net.NetworkInformation/IcmpV6Statistics.cs
mcs/class/System/System.Net.NetworkInformation/TcpConnectionInformation.cs
mcs/class/System/System.Net.NetworkInformation/TcpStatistics.cs
mcs/class/System/System.Net.NetworkInformation/UdpStatistics.cs

index 6f14725505530d83a59cb56825f7b2a6242b3dae..55a739c5f646f5251a161d6c9ded96818713b375 100644 (file)
@@ -1,3 +1,12 @@
+2007-08-27  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * IPGlobalProperties.cs, TcpConnectionInformation.cs,
+         TcpStatistics.cs, IPGlobalStatistics.cs, IcmpV4Statistics.cs,
+         IcmpV6Statistics.cs, UdpStatistics.cs :
+         initial implementation of IPGlobalProperties and its children
+         for Win32 API, mostly done. Non-Windows implementation should
+         follow.
+
 2007-08-13  Alan McGovern  <amcgovern@novell.com>
 
        * PhysicalAddress.cs: Added patch for #82403 to fix some parsing
index 94410bff94da7257518ead3e6fd9f13da82f232a..bbe831db7f2a9c440ff08f16bb636895d525ea82 100644 (file)
@@ -1,10 +1,11 @@
 //
 // System.Net.NetworkInformation.IPGlobalProperties
 //
-// Author:
+// Authors:
 //     Gonzalo Paniagua Javier (gonzalo@novell.com)
+//     Atsushi Enomoto (atsushi@ximian.com)
 //
-// Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
+// Copyright (c) 2006-2007 Novell, Inc. (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 #if NET_2_0
+using System.Net.Sockets;
+using System.Runtime.InteropServices;
+
 namespace System.Net.NetworkInformation {
        public abstract class IPGlobalProperties {
                protected IPGlobalProperties ()
                {
                }
 
-               [MonoTODO]
+               [MonoTODO ("Unimplemented on non-Windows. A marshalling issue on Windows")]
                public static IPGlobalProperties GetIPGlobalProperties ()
                {
-                       throw new NotImplementedException ();
+                       switch (Environment.OSVersion.Platform) {
+                       case PlatformID.Unix:
+                               throw new NotImplementedException ();
+                       default:
+                               return new Win32IPGlobalProperties ();
+                       }
                }
 
                public abstract TcpConnectionInformation [] GetActiveTcpConnections ();
@@ -56,6 +65,347 @@ namespace System.Net.NetworkInformation {
                public abstract bool IsWinsProxy { get; }
                public abstract NetBiosNodeType NodeType { get; }
        }
+
+       class Win32IPGlobalProperties : IPGlobalProperties
+       {
+               public const int AF_INET = 2;
+               public const int AF_INET6 = 23;
+
+               // FIXME: fails at some marshaling stage
+               void FillTcpTable (out Win32_MIB_TCPTABLE tab4, out Win32_MIB_TCP6TABLE tab6)
+               {
+                       tab4 = null;
+                       int size4 = 0;
+                       GetTcpTable (ref tab4, ref size4, false); // get size
+                       tab4 = new Win32_MIB_TCPTABLE (size4);
+                       GetTcpTable (ref tab4, ref size4, false); // get list
+                       tab6 = null;
+                       int size6 = 0;
+                       GetTcp6Table (ref tab6, ref size6, false); // get size
+                       tab6 = new Win32_MIB_TCP6TABLE (size6);
+                       GetTcp6Table (ref tab6, ref size6, false); // get list
+
+               }
+
+               public override TcpConnectionInformation [] GetActiveTcpConnections ()
+               {
+                       Win32_MIB_TCPTABLE tab4 = null;
+                       Win32_MIB_TCP6TABLE tab6 = null;
+                       FillTcpTable (out tab4, out tab6);
+                       int size4 = tab4.Table.Length;
+
+                       TcpConnectionInformation [] ret = new TcpConnectionInformation [size4 + tab6.Table.Length];
+                       for (int i = 0; i < size4; i++)
+                               ret [i] = tab4.Table [i].TcpInfo;
+                       for (int i = 0; i < tab6.Table.Length; i++)
+                               ret [size4 + i] = tab6.Table [i].TcpInfo;
+                       return ret;
+               }
+
+               public override IPEndPoint [] GetActiveTcpListeners ()
+               {
+                       Win32_MIB_TCPTABLE tab4 = null;
+                       Win32_MIB_TCP6TABLE tab6 = null;
+                       FillTcpTable (out tab4, out tab6);
+                       int size4 = tab4.Table.Length;
+
+                       IPEndPoint [] ret = new IPEndPoint [size4 + tab6.Table.Length];
+                       for (int i = 0; i < size4; i++)
+                               ret [i] = tab4.Table [i].LocalEndPoint;
+                       for (int i = 0; i < tab6.Table.Length; i++)
+                               ret [size4 + i] = tab6.Table [i].LocalEndPoint;
+                       return ret;
+               }
+
+               // FIXME: fails at some marshaling stage
+               public override IPEndPoint [] GetActiveUdpListeners ()
+               {
+                       Win32_MIB_UDPTABLE tab4 = null;
+                       int size4 = 0;
+                       GetUdpTable (ref tab4, ref size4, false); // get size
+                       tab4 = new Win32_MIB_UDPTABLE (size4);
+                       GetUdpTable (ref tab4, ref size4, false); // get list
+                       Win32_MIB_UDP6TABLE tab6 = null;
+                       int size6 = 0;
+                       GetUdp6Table (ref tab6, ref size6, false); // get size
+                       tab6 = new Win32_MIB_UDP6TABLE (size6);
+                       GetUdp6Table (ref tab6, ref size6, false); // get list
+
+                       IPEndPoint [] ret = new IPEndPoint [size4 + size6];
+                       for (int i = 0; i < size4; i++)
+                               ret [i] = tab4.Table [i].LocalEndPoint;
+                       for (int i = 0; i < size6; i++)
+                               ret [size4 + i] = tab6.Table [i].LocalEndPoint;
+                       return ret;
+               }
+
+               public override IcmpV4Statistics GetIcmpV4Statistics ()
+               {
+                       if (!Socket.SupportsIPv4)
+                               throw new NetworkInformationException ();
+                       Win32_MIBICMPINFO stats;
+                       GetIcmpStatistics (out stats, AF_INET);
+                       return new Win32IcmpV4Statistics (stats);
+               }
+
+               public override IcmpV6Statistics GetIcmpV6Statistics ()
+               {
+                       if (!Socket.OSSupportsIPv6)
+                               throw new NetworkInformationException ();
+                       Win32_MIB_ICMP_EX stats;
+                       GetIcmpStatisticsEx (out stats, AF_INET6);
+                       return new Win32IcmpV6Statistics (stats);
+               }
+
+               public override IPGlobalStatistics GetIPv4GlobalStatistics ()
+               {
+                       if (!Socket.SupportsIPv4)
+                               throw new NetworkInformationException ();
+                       Win32_MIB_IPSTATS stats;
+                       GetIPStatisticsEx (out stats, AF_INET);
+                       return new Win32IPGlobalStatistics (stats);
+               }
+
+               public override IPGlobalStatistics GetIPv6GlobalStatistics ()
+               {
+                       if (!Socket.OSSupportsIPv6)
+                               throw new NetworkInformationException ();
+                       Win32_MIB_IPSTATS stats;
+                       GetIPStatisticsEx (out stats, AF_INET6);
+                       return new Win32IPGlobalStatistics (stats);
+               }
+
+               public override TcpStatistics GetTcpIPv4Statistics ()
+               {
+                       if (!Socket.SupportsIPv4)
+                               throw new NetworkInformationException ();
+                       Win32_MIB_TCPSTATS stats;
+                       GetTcpStatisticsEx (out stats, AF_INET);
+                       return new Win32TcpStatistics (stats);
+               }
+
+               public override TcpStatistics GetTcpIPv6Statistics ()
+               {
+                       if (!Socket.OSSupportsIPv6)
+                               throw new NetworkInformationException ();
+                       Win32_MIB_TCPSTATS stats;
+                       GetTcpStatisticsEx (out stats, AF_INET6);
+                       return new Win32TcpStatistics (stats);
+               }
+
+               public override UdpStatistics GetUdpIPv4Statistics ()
+               {
+                       if (!Socket.SupportsIPv4)
+                               throw new NetworkInformationException ();
+                       Win32_MIB_UDPSTATS stats;
+                       GetUdpStatisticsEx (out stats, AF_INET);
+                       return new Win32UdpStatistics (stats);
+               }
+
+               public override UdpStatistics GetUdpIPv6Statistics ()
+               {
+                       if (!Socket.OSSupportsIPv6)
+                               throw new NetworkInformationException ();
+                       Win32_MIB_UDPSTATS stats;
+                       GetUdpStatisticsEx (out stats, AF_INET6);
+                       return new Win32UdpStatistics (stats);
+               }
+
+               public override string DhcpScopeName {
+                       get { throw new NotImplementedException (); }
+               }
+
+               public override string DomainName {
+                       get { throw new NotImplementedException (); }
+               }
+
+               public override string HostName {
+                       get { throw new NotImplementedException (); }
+               }
+
+               public override bool IsWinsProxy {
+                       get { throw new NotImplementedException (); }
+               }
+
+               public override NetBiosNodeType NodeType {
+                       get { throw new NotImplementedException (); }
+               }
+
+               // PInvokes
+
+               [DllImport ("Iphlpapi.dll")]
+               static extern int GetTcpTable (ref Win32_MIB_TCPTABLE pTcpTable, ref int pdwSize, bool bOrder);
+
+               [DllImport ("Iphlpapi.dll")]
+               static extern int GetTcp6Table (ref Win32_MIB_TCP6TABLE TcpTable, ref int SizePointer, bool Order);
+
+               [DllImport ("Iphlpapi.dll")]
+               static extern int GetUdpTable (ref Win32_MIB_UDPTABLE pUdpTable, ref int pdwSize, bool bOrder);
+
+               [DllImport ("Iphlpapi.dll")]
+               static extern int GetUdp6Table (ref Win32_MIB_UDP6TABLE Udp6Table, ref int SizePointer, bool Order);
+
+               [DllImport ("Iphlpapi.dll")]
+               static extern int GetTcpStatisticsEx (out Win32_MIB_TCPSTATS pStats, int dwFamily);
+
+               [DllImport ("Iphlpapi.dll")]
+               static extern int GetUdpStatisticsEx (out Win32_MIB_UDPSTATS pStats, int dwFamily);
+
+               [DllImport ("Iphlpapi.dll")]
+               static extern int GetIcmpStatistics (out Win32_MIBICMPINFO pStats, int dwFamily);
+
+               [DllImport ("Iphlpapi.dll")]
+               static extern int GetIcmpStatisticsEx (out Win32_MIB_ICMP_EX pStats, int dwFamily);
+
+               [DllImport ("Iphlpapi.dll")]
+               static extern int GetIPStatisticsEx (out Win32_MIB_IPSTATS pStats, int dwFamily);
+
+               // Win32 structures
+
+               [StructLayout (LayoutKind.Explicit)]
+               struct Win32_IN6_ADDR
+               {
+                       [FieldOffset (0)]
+                       [MarshalAs ((short) UnmanagedType.U1, SizeConst = 16)]
+                       public byte [] Bytes;
+                       [FieldOffset (0)]
+                       [MarshalAs ((short) UnmanagedType.U2, SizeConst = 8)]
+                       public byte [] UInt16Array;
+                       [FieldOffset (0)]
+                       [MarshalAs ((short) UnmanagedType.U4, SizeConst = 4)]
+                       public byte [] UInt32Array;
+               }
+
+               [StructLayout (LayoutKind.Sequential)]
+               class Win32_MIB_TCPTABLE
+               {
+                       public int NumEntries;
+                       // FIXME: looks like it is wrong
+                       [MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_USERDEFINED, SafeArrayUserDefinedSubType = typeof (Win32_MIB_TCPROW))]
+                       public Win32_MIB_TCPROW [] Table;
+
+                       public Win32_MIB_TCPTABLE (int size)
+                       {
+                               NumEntries = size;
+                               Table = new Win32_MIB_TCPROW [size];
+                       }
+               }
+
+               [StructLayout (LayoutKind.Sequential)]
+               struct Win32_MIB_TCPROW
+               {
+                       public TcpState State;
+                       public uint LocalAddr;
+                       public int LocalPort;
+                       public uint RemoteAddr;
+                       public int RemotePort;
+
+                       public IPEndPoint LocalEndPoint {
+                               get { return new IPEndPoint (LocalAddr, LocalPort); }
+                       }
+
+                       public IPEndPoint RemoteEndPoint {
+                               get { return new IPEndPoint (RemoteAddr, RemotePort); }
+                       }
+
+                       public TcpConnectionInformation TcpInfo {
+                               get { return new TcpConnectionInformationImpl (LocalEndPoint, RemoteEndPoint, State); }
+                       }
+               }
+
+               [StructLayout (LayoutKind.Sequential)]
+               class Win32_MIB_TCP6TABLE
+               {
+                       public int NumEntries;
+                       // FIXME: looks like it is wrong
+                       [MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_USERDEFINED, SafeArrayUserDefinedSubType = typeof (Win32_MIB_TCP6ROW))]
+                       public Win32_MIB_TCP6ROW [] Table;
+
+                       public Win32_MIB_TCP6TABLE (int size)
+                       {
+                               NumEntries = size;
+                               Table = new Win32_MIB_TCP6ROW [size];
+                       }
+               }
+
+               [StructLayout (LayoutKind.Sequential)]
+               struct Win32_MIB_TCP6ROW
+               {
+                       public TcpState State;
+                       public Win32_IN6_ADDR LocalAddr;
+                       public uint LocalScopeId;
+                       public int LocalPort;
+                       public Win32_IN6_ADDR RemoteAddr;
+                       public uint RemoteScopeId;
+                       public int RemotePort;
+
+                       public IPEndPoint LocalEndPoint {
+                               get { return new IPEndPoint (new IPAddress (LocalAddr.Bytes, LocalScopeId), LocalPort); }
+                       }
+
+                       public IPEndPoint RemoteEndPoint {
+                               get { return new IPEndPoint (new IPAddress (RemoteAddr.Bytes, RemoteScopeId), RemotePort); }
+                       }
+
+                       public TcpConnectionInformation TcpInfo {
+                               get { return new TcpConnectionInformationImpl (LocalEndPoint, RemoteEndPoint, State); }
+                       }
+               }
+
+               [StructLayout (LayoutKind.Sequential)]
+               class Win32_MIB_UDPTABLE
+               {
+                       public int NumEntries;
+                       // FIXME: looks like it is wrong
+                       [MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_USERDEFINED, SafeArrayUserDefinedSubType = typeof (Win32_MIB_UDPROW))]
+                       public Win32_MIB_UDPROW [] Table;
+
+                       public Win32_MIB_UDPTABLE (int size)
+                       {
+                               NumEntries = size;
+                               Table = new Win32_MIB_UDPROW [size];
+                       }
+               }
+
+               [StructLayout (LayoutKind.Sequential)]
+               struct Win32_MIB_UDPROW
+               {
+                       public uint LocalAddr;
+                       public int LocalPort;
+
+                       public IPEndPoint LocalEndPoint {
+                               get { return new IPEndPoint (LocalAddr, LocalPort); }
+                       }
+               }
+
+               [StructLayout (LayoutKind.Sequential)]
+               class Win32_MIB_UDP6TABLE
+               {
+                       public int NumEntries;
+                       // FIXME: looks like it is wrong
+                       [MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_USERDEFINED, SafeArrayUserDefinedSubType = typeof (Win32_MIB_UDP6ROW))]
+                       public Win32_MIB_UDP6ROW [] Table;
+
+                       public Win32_MIB_UDP6TABLE (int size)
+                       {
+                               NumEntries = size;
+                               Table = new Win32_MIB_UDP6ROW [size];
+                       }
+               }
+
+               [StructLayout (LayoutKind.Sequential)]
+               struct Win32_MIB_UDP6ROW
+               {
+                       public Win32_IN6_ADDR LocalAddr;
+                       public uint LocalScopeId;
+                       public int LocalPort;
+
+                       public IPEndPoint LocalEndPoint {
+                               get { return new IPEndPoint (new IPAddress (LocalAddr.Bytes, LocalScopeId), LocalPort); }
+                       }
+               }
+
+       }
 }
 #endif
 
index 03b8388d03454f86332fec3a192a61deb6c8bcc8..16027021ed58bf3a705e11e49ee575cae5a4ce73 100644 (file)
@@ -1,10 +1,11 @@
 //
 // System.Net.NetworkInformation.IPGlobalProperties
 //
-// Author:
+// Authors:
 //     Gonzalo Paniagua Javier (gonzalo@novell.com)
+//     Atsushi Enomoto (atsushi@ximian.com)
 //
-// Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
+// Copyright (c) 2006-2007 Novell, Inc. (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -55,6 +56,110 @@ namespace System.Net.NetworkInformation {
                public abstract long ReceivedPacketsWithHeadersErrors { get; }
                public abstract long ReceivedPacketsWithUnknownProtocol { get; }
        }
+
+       class Win32IPGlobalStatistics : IPGlobalStatistics 
+       {
+               Win32_MIB_IPSTATS info;
+
+               public Win32IPGlobalStatistics (Win32_MIB_IPSTATS info)
+               {
+                       this.info = info;
+               }
+
+               public override int DefaultTtl {
+                       get { return info.DefaultTTL; }
+               }
+               public override bool ForwardingEnabled {
+                       get { return info.Forwarding != 0; }
+               }
+               public override int NumberOfInterfaces {
+                       get { return info.NumIf; }
+               }
+               public override int NumberOfIPAddresses {
+                       get { return info.NumAddr; }
+               }
+               public override int NumberOfRoutes {
+                       get { return info.NumRoutes; }
+               }
+               public override long OutputPacketRequests {
+                       get { return info.OutRequests; }
+               }
+               public override long OutputPacketRoutingDiscards {
+                       get { return info.RoutingDiscards; }
+               }
+               public override long OutputPacketsDiscarded {
+                       get { return info.OutDiscards; }
+               }
+               public override long OutputPacketsWithNoRoute {
+                       get { return info.OutNoRoutes; }
+               }
+               public override long PacketFragmentFailures {
+                       get { return info.FragFails; }
+               }
+               public override long PacketReassembliesRequired {
+                       get { return info.ReasmReqds; }
+               }
+               public override long PacketReassemblyFailures {
+                       get { return info.ReasmFails; }
+               }
+               public override long PacketReassemblyTimeout {
+                       get { return info.ReasmTimeout; }
+               }
+               public override long PacketsFragmented {
+                       get { return info.FragOks; }
+               }
+               public override long PacketsReassembled {
+                       get { return info.ReasmOks; }
+               }
+               public override long ReceivedPackets {
+                       get { return info.InReceives; }
+               }
+               public override long ReceivedPacketsDelivered {
+                       get { return info.InDelivers; }
+               }
+               public override long ReceivedPacketsDiscarded {
+                       get { return info.InDiscards; }
+               }
+               public override long ReceivedPacketsForwarded {
+                       get { return info.ForwDatagrams; }
+               }
+               public override long ReceivedPacketsWithAddressErrors {
+                       get { return info.InAddrErrors; }
+               }
+               public override long ReceivedPacketsWithHeadersErrors {
+                       get { return info.InHdrErrors; }
+               }
+               public override long ReceivedPacketsWithUnknownProtocol {
+                       get { return info.InUnknownProtos; }
+               }
+       }
+
+       struct Win32_MIB_IPSTATS
+       {
+               public int Forwarding;
+               public int DefaultTTL;
+               public uint InReceives;
+               public uint InHdrErrors;
+               public uint InAddrErrors;
+               public uint ForwDatagrams;
+               public uint InUnknownProtos;
+               public uint InDiscards;
+               public uint InDelivers;
+               public uint OutRequests;
+               public uint RoutingDiscards;
+               public uint OutDiscards;
+               public uint OutNoRoutes;
+               public uint ReasmTimeout;
+               public uint ReasmReqds;
+               public uint ReasmOks;
+               public uint ReasmFails;
+               public uint FragOks;
+               public uint FragFails;
+               public uint FragCreates;
+               public int NumIf;
+               public int NumAddr;
+               public int NumRoutes;
+       }
 }
 #endif
 
index eebe240fa7d557e32dc75df208e3a590029e12f4..9bde514fde5fe1266f92f7263aff163aa4e22289 100644 (file)
@@ -1,10 +1,11 @@
 //
 // System.Net.NetworkInformation.IcmpV4Statistics
 //
-// Author:
+// Authors:
 //     Gonzalo Paniagua Javier (gonzalo@novell.com)
+//     Atsushi Enomoto (atsushi@ximian.com)
 //
-// Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
+// Copyright (c) 2006-2007 Novell, Inc. (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -59,6 +60,119 @@ namespace System.Net.NetworkInformation {
                public abstract long TimestampRequestsReceived { get; }
                public abstract long TimestampRequestsSent { get; }
        }
+
+       class Win32IcmpV4Statistics : IcmpV4Statistics
+       {
+               Win32_MIBICMPSTATS iin, iout;
+
+               public Win32IcmpV4Statistics (Win32_MIBICMPINFO info)
+               {
+                       iin = info.InStats;
+                       iout = info.OutStats;
+               }
+
+               public override long AddressMaskRepliesReceived {
+                       get { return iin.AddrMaskReps; }
+               }
+               public override long AddressMaskRepliesSent {
+                       get { return iout.AddrMaskReps; }
+               }
+               public override long AddressMaskRequestsReceived {
+                       get { return iin.AddrMasks; }
+               }
+               public override long AddressMaskRequestsSent {
+                       get { return iout.AddrMasks; }
+               }
+               public override long DestinationUnreachableMessagesReceived {
+                       get { return iin.DestUnreachs; }
+               }
+               public override long DestinationUnreachableMessagesSent {
+                       get { return iout.DestUnreachs; }
+               }
+               public override long EchoRepliesReceived {
+                       get { return iin.EchoReps; }
+               }
+               public override long EchoRepliesSent {
+                       get { return iout.EchoReps; }
+               }
+               public override long EchoRequestsReceived {
+                       get { return iin.Echos; }
+               }
+               public override long EchoRequestsSent {
+                       get { return iout.Echos; }
+               }
+               public override long ErrorsReceived {
+                       get { return iin.Errors; }
+               }
+               public override long ErrorsSent {
+                       get { return iout.Errors; }
+               }
+               public override long MessagesReceived {
+                       get { return iin.Msgs; }
+               }
+               public override long MessagesSent {
+                       get { return iout.Msgs; }
+               }
+               public override long ParameterProblemsReceived {
+                       get { return iin.ParmProbs; }
+               }
+               public override long ParameterProblemsSent {
+                       get { return iout.ParmProbs; }
+               }
+               public override long RedirectsReceived {
+                       get { return iin.Redirects; }
+               }
+               public override long RedirectsSent {
+                       get { return iout.Redirects; }
+               }
+               public override long SourceQuenchesReceived {
+                       get { return iin.SrcQuenchs; }
+               }
+               public override long SourceQuenchesSent {
+                       get { return iout.SrcQuenchs; }
+               }
+               public override long TimeExceededMessagesReceived {
+                       get { return iin.TimeExcds; }
+               }
+               public override long TimeExceededMessagesSent {
+                       get { return iout.TimeExcds; }
+               }
+               public override long TimestampRepliesReceived {
+                       get { return iin.TimestampReps; }
+               }
+               public override long TimestampRepliesSent {
+                       get { return iout.TimestampReps; }
+               }
+               public override long TimestampRequestsReceived {
+                       get { return iin.Timestamps; }
+               }
+               public override long TimestampRequestsSent {
+                       get { return iout.Timestamps; }
+               }
+       }
+
+       struct Win32_MIBICMPINFO
+       {
+               public Win32_MIBICMPSTATS InStats;
+               public Win32_MIBICMPSTATS OutStats;
+       }
+
+       struct Win32_MIBICMPSTATS
+       {
+               public uint Msgs;
+               public uint Errors;
+               public uint DestUnreachs;
+               public uint TimeExcds;
+               public uint ParmProbs;
+               public uint SrcQuenchs;
+               public uint Redirects;
+               public uint Echos;
+               public uint EchoReps;
+               public uint Timestamps;
+               public uint TimestampReps;
+               public uint AddrMasks;
+               public uint AddrMaskReps;
+       }
 }
 #endif
 
index f925876fff6289b2cb0be7463a77345d94609c03..9c8ee59871de72d495187f60c7f63fcf65de4c88 100644 (file)
@@ -1,10 +1,11 @@
 //
 // System.Net.NetworkInformation.IcmpV6Statistics
 //
-// Author:
+// Authors:
 //     Gonzalo Paniagua Javier (gonzalo@novell.com)
+//     Atsushi Enomoto (atsushi@ximian.com)
 //
-// Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
+// Copyright (c) 2006-2007 Novell, Inc. (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -26,6 +27,8 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 #if NET_2_0
+using System.Runtime.InteropServices;
+
 namespace System.Net.NetworkInformation {
        public abstract class IcmpV6Statistics {
                protected IcmpV6Statistics ()
@@ -65,6 +68,147 @@ namespace System.Net.NetworkInformation {
                public abstract long TimeExceededMessagesReceived { get; }
                public abstract long TimeExceededMessagesSent { get; }
        }
+
+       class IcmpV6MessageTypes
+       {
+               public const int DestinationUnreachable = 1;
+               public const int PacketTooBig = 2;
+               public const int TimeExceeded = 3;
+               public const int ParameterProblem = 4;
+               public const int EchoRequest = 128;
+               public const int EchoReply = 129;
+               public const int GroupMembershipQuery = 130;
+               public const int GroupMembershipReport = 131;
+               public const int GroupMembershipReduction = 132;
+               public const int RouterSolicitation = 133;
+               public const int RouterAdvertisement = 134;
+               public const int NeighborSolicitation = 135;
+               public const int NeighborAdvertisement = 136;
+               public const int Redirect = 137;
+               public const int RouterRenumbering = 138;
+       }
+
+       class Win32IcmpV6Statistics : IcmpV6Statistics
+       {
+               Win32_MIBICMPSTATS_EX iin, iout;
+
+               public Win32IcmpV6Statistics (Win32_MIB_ICMP_EX info)
+               {
+                       iin = info.InStats;
+                       iout = info.OutStats;
+               }
+
+               public override long DestinationUnreachableMessagesReceived {
+                       get { return iin.Counts [IcmpV6MessageTypes.DestinationUnreachable]; }
+               }
+               public override long DestinationUnreachableMessagesSent {
+                       get { return iout.Counts [IcmpV6MessageTypes.DestinationUnreachable]; }
+               }
+               public override long EchoRepliesReceived {
+                       get { return iin.Counts [IcmpV6MessageTypes.EchoReply]; }
+               }
+               public override long EchoRepliesSent {
+                       get { return iout.Counts [IcmpV6MessageTypes.EchoReply]; }
+               }
+               public override long EchoRequestsReceived {
+                       get { return iin.Counts [IcmpV6MessageTypes.EchoRequest]; }
+               }
+               public override long EchoRequestsSent {
+                       get { return iout.Counts [IcmpV6MessageTypes.EchoRequest]; }
+               }
+               public override long ErrorsReceived {
+                       get { return iin.Errors; }
+               }
+               public override long ErrorsSent {
+                       get { return iout.Errors; }
+               }
+               public override long MembershipQueriesReceived {
+                       get { return iin.Counts [IcmpV6MessageTypes.GroupMembershipQuery]; }
+               }
+               public override long MembershipQueriesSent {
+                       get { return iout.Counts [IcmpV6MessageTypes.GroupMembershipQuery]; }
+               }
+               public override long MembershipReductionsReceived {
+                       get { return iin.Counts [IcmpV6MessageTypes.GroupMembershipReduction]; }
+               }
+               public override long MembershipReductionsSent {
+                       get { return iout.Counts [IcmpV6MessageTypes.GroupMembershipReduction]; }
+               }
+               public override long MembershipReportsReceived {
+                       get { return iin.Counts [IcmpV6MessageTypes.GroupMembershipReport]; }
+               }
+               public override long MembershipReportsSent {
+                       get { return iout.Counts [IcmpV6MessageTypes.GroupMembershipReport]; }
+               }
+               public override long MessagesReceived {
+                       get { return iin.Msgs; }
+               }
+               public override long MessagesSent {
+                       get { return iout.Msgs; }
+               }
+               public override long NeighborAdvertisementsReceived {
+                       get { return iin.Counts [IcmpV6MessageTypes.NeighborAdvertisement]; }
+               }
+               public override long NeighborAdvertisementsSent {
+                       get { return iout.Counts [IcmpV6MessageTypes.NeighborAdvertisement]; }
+               }
+               public override long NeighborSolicitsReceived {
+                       get { return iin.Counts [IcmpV6MessageTypes.NeighborSolicitation]; }
+               }
+               public override long NeighborSolicitsSent {
+                       get { return iout.Counts [IcmpV6MessageTypes.NeighborSolicitation]; }
+               }
+               public override long PacketTooBigMessagesReceived {
+                       get { return iin.Counts [IcmpV6MessageTypes.PacketTooBig]; }
+               }
+               public override long PacketTooBigMessagesSent {
+                       get { return iout.Counts [IcmpV6MessageTypes.PacketTooBig]; }
+               }
+               public override long ParameterProblemsReceived {
+                       get { return iin.Counts [IcmpV6MessageTypes.ParameterProblem]; }
+               }
+               public override long ParameterProblemsSent {
+                       get { return iout.Counts [IcmpV6MessageTypes.ParameterProblem]; }
+               }
+               public override long RedirectsReceived {
+                       get { return iin.Counts [IcmpV6MessageTypes.Redirect]; }
+               }
+               public override long RedirectsSent {
+                       get { return iout.Counts [IcmpV6MessageTypes.Redirect]; }
+               }
+               public override long RouterAdvertisementsReceived {
+                       get { return iin.Counts [IcmpV6MessageTypes.RouterAdvertisement]; }
+               }
+               public override long RouterAdvertisementsSent {
+                       get { return iout.Counts [IcmpV6MessageTypes.RouterAdvertisement]; }
+               }
+               public override long RouterSolicitsReceived {
+                       get { return iin.Counts [IcmpV6MessageTypes.RouterSolicitation]; }
+               }
+               public override long RouterSolicitsSent {
+                       get { return iout.Counts [IcmpV6MessageTypes.RouterSolicitation]; }
+               }
+               public override long TimeExceededMessagesReceived {
+                       get { return iin.Counts [IcmpV6MessageTypes.TimeExceeded]; }
+               }
+               public override long TimeExceededMessagesSent {
+                       get { return iout.Counts [IcmpV6MessageTypes.TimeExceeded]; }
+               }
+       }
+
+       struct Win32_MIB_ICMP_EX
+       {
+               public Win32_MIBICMPSTATS_EX InStats;
+               public Win32_MIBICMPSTATS_EX OutStats;
+       }
+
+       struct Win32_MIBICMPSTATS_EX
+       {
+               public uint Msgs;
+               public uint Errors;
+               [MarshalAs (UnmanagedType.ByValArray, SizeConst = 256)]
+               public uint [] Counts;
+       }
 }
 #endif
 
index 272d5d837e3696572c8564648049f59d059400dc..48ef22ff16289fbf565e74aeb3e7c8dabdeda10d 100644 (file)
@@ -1,10 +1,11 @@
 //
 // System.Net.NetworkInformation.TcpConnectionInformation
 //
-// Author:
+// Authors:
 //     Gonzalo Paniagua Javier (gonzalo@novell.com)
+//     Atsushi Enomoto (atsushi@ximian.com)
 //
-// Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
+// Copyright (c) 2006-2007 Novell, Inc. (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -38,6 +39,30 @@ namespace System.Net.NetworkInformation {
                public abstract IPEndPoint RemoteEndPoint { get; }
                public abstract TcpState State { get; }
        }
+
+       class TcpConnectionInformationImpl : TcpConnectionInformation
+       {
+               IPEndPoint local;
+               IPEndPoint remote;
+               TcpState state;
+
+               public TcpConnectionInformationImpl (IPEndPoint local, IPEndPoint remote, TcpState state)
+               {
+                       this.local = local;
+                       this.remote = remote;
+                       this.state = state;
+               }
+
+               public override IPEndPoint LocalEndPoint {
+                       get { return local; }
+               }
+               public override IPEndPoint RemoteEndPoint {
+                       get { return remote; }
+               }
+               public override TcpState State {
+                       get { return state; }
+               }
+       }
 }
 #endif
 
index 5f8bb3cc87959e0e49bd9141824e175d3de38e3d..60f249db8fe0024604345e6db16cd3485e56443b 100644 (file)
@@ -1,10 +1,11 @@
 //
 // System.Net.NetworkInformation.TcpStatistics
 //
-// Author:
+// Authors:
 //     Gonzalo Paniagua Javier (gonzalo@novell.com)
+//     Atsushi Enomoto (atsushi@ximian.com)
 //
-// Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
+// Copyright (c) 2006-2007 Novell, Inc. (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -47,6 +48,92 @@ namespace System.Net.NetworkInformation {
                public abstract long SegmentsResent { get; }
                public abstract long SegmentsSent { get; }
        }
+
+       class Win32TcpStatistics : TcpStatistics
+       {
+               Win32_MIB_TCPSTATS info;
+
+               public Win32TcpStatistics (Win32_MIB_TCPSTATS info)
+               {
+                       this.info = info;
+               }
+
+               public override long ConnectionsAccepted {
+                       get { return info.PassiveOpens; }
+               }
+
+               public override long ConnectionsInitiated {
+                       get { return info.ActiveOpens; }
+               }
+
+               public override long CumulativeConnections {
+                       get { return info.NumConns; }
+               }
+
+               public override long CurrentConnections {
+                       get { return info.CurrEstab; }
+               }
+
+               public override long ErrorsReceived {
+                       get { return info.InErrs; }
+               }
+
+               public override long FailedConnectionAttempts {
+                       get { return info.AttemptFails; }
+               }
+
+               public override long MaximumConnections {
+                       get { return info.MaxConn; }
+               }
+
+               public override long MaximumTransmissionTimeout {
+                       get { return info.RtoMax; }
+               }
+
+               public override long MinimumTransmissionTimeout {
+                       get { return info.RtoMin; }
+               }
+
+               public override long ResetConnections {
+                       get { return info.EstabResets; }
+               }
+
+               public override long ResetsSent {
+                       get { return info.OutRsts; }
+               }
+
+               public override long SegmentsReceived {
+                       get { return info.InSegs; }
+               }
+
+               public override long SegmentsResent {
+                       get { return info.RetransSegs; }
+               }
+
+               public override long SegmentsSent {
+                       get { return info.OutSegs; }
+               }
+       }
+
+       struct Win32_MIB_TCPSTATS
+       {
+               public uint RtoAlgorithm;
+               public uint RtoMin;
+               public uint RtoMax;
+               public uint MaxConn;
+               public uint ActiveOpens;
+               public uint PassiveOpens;
+               public uint AttemptFails;
+               public uint EstabResets;
+               public uint CurrEstab;
+               public uint InSegs;
+               public uint OutSegs;
+               public uint RetransSegs;
+               public uint InErrs;
+               public uint OutRsts;
+               public uint NumConns;
+       }
+
 }
 #endif
 
index 8055046095b21f7030579444aed1e8debe1bf675..22defefb585d0a3453141a3f48af4b03d9f38fd3 100644 (file)
@@ -1,10 +1,11 @@
 //
 // System.Net.NetworkInformation.UdpStatistics
 //
-// Author:
+// Authors:
 //     Gonzalo Paniagua Javier (gonzalo@novell.com)
+//     Atsushi Enomoto (atsushi@ximian.com)
 //
-// Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
+// Copyright (c) 2006-2007 Novell, Inc. (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -38,6 +39,45 @@ namespace System.Net.NetworkInformation {
                public abstract long IncomingDatagramsWithErrors { get; }
                public abstract int UdpListeners { get; }
        }
+
+       class Win32UdpStatistics : UdpStatistics
+       {
+               Win32_MIB_UDPSTATS info;
+
+               public Win32UdpStatistics (Win32_MIB_UDPSTATS info)
+               {
+                       this.info = info;
+               }
+
+               public override long DatagramsReceived {
+                       get { return info.InDatagrams; }
+               }
+
+               public override long DatagramsSent {
+                       get { return info.OutDatagrams; }
+               }
+
+               public override long IncomingDatagramsDiscarded {
+                       get { return info.NoPorts; }
+               }
+
+               public override long IncomingDatagramsWithErrors {
+                       get { return info.InErrors; }
+               }
+
+               public override int UdpListeners {
+                       get { return info.NumAddrs; }
+               }
+       }
+
+       struct Win32_MIB_UDPSTATS
+       {
+               public uint InDatagrams;
+               public uint NoPorts;
+               public uint InErrors;
+               public uint OutDatagrams;
+               public int NumAddrs;
+       }
 }
 #endif