// Authors:
// Gonzalo Paniagua Javier (gonzalo@novell.com)
// Atsushi Enomoto (atsushi@ximian.com)
+// Marek Safar (marek.safar@gmail.com)
//
// Copyright (c) 2006-2007 Novell, Inc. (http://www.novell.com)
//
using System.Text;
namespace System.Net.NetworkInformation {
- public abstract class IPGlobalProperties {
- protected IPGlobalProperties ()
+ abstract class CommonUnixIPGlobalProperties : IPGlobalProperties
+ {
+ [DllImport ("libc")]
+ static extern int gethostname ([MarshalAs (UnmanagedType.LPArray, SizeParamIndex = 1)] byte [] name, int len);
+
+ [DllImport ("libc")]
+ static extern int getdomainname ([MarshalAs (UnmanagedType.LPArray, SizeParamIndex = 1)] byte [] name, int len);
+
+ public override string DhcpScopeName {
+ get { return String.Empty; }
+ }
+
+ public override string DomainName {
+ get {
+ byte [] bytes = new byte [256];
+ if (getdomainname (bytes, 256) != 0)
+ throw new NetworkInformationException ();
+ int len = Array.IndexOf<byte> (bytes, 0);
+ return Encoding.ASCII.GetString (bytes, 0, len < 0 ? 256 : len);
+ }
+ }
+
+ public override string HostName {
+ get {
+ byte [] bytes = new byte [256];
+ if (gethostname (bytes, 256) != 0)
+ throw new NetworkInformationException ();
+ int len = Array.IndexOf<byte> (bytes, 0);
+ return Encoding.ASCII.GetString (bytes, 0, len < 0 ? 256 : len);
+ }
+ }
+
+ public override bool IsWinsProxy {
+ get { return false; } // no WINS
+ }
+
+ public override NetBiosNodeType NodeType {
+ get { return NetBiosNodeType.Unknown; } // no NetBios
+ }
+ }
+
+ class UnixIPGlobalProperties : CommonUnixIPGlobalProperties
+ {
+ public override TcpConnectionInformation [] GetActiveTcpConnections ()
{
+ throw new NotImplementedException ();
}
- public static IPGlobalProperties GetIPGlobalProperties ()
+ public override IPEndPoint [] GetActiveTcpListeners ()
{
- switch (Environment.OSVersion.Platform) {
- case PlatformID.Unix:
- MibIPGlobalProperties impl = null;
- if (Directory.Exists (MibIPGlobalProperties.ProcDir)) {
- impl = new MibIPGlobalProperties (MibIPGlobalProperties.ProcDir);
- if (File.Exists (impl.StatisticsFile))
- return impl;
- }
- if (Directory.Exists (MibIPGlobalProperties.CompatProcDir)) {
- impl = new MibIPGlobalProperties (MibIPGlobalProperties.CompatProcDir);
- if (File.Exists (impl.StatisticsFile))
- return impl;
- }
- throw new NotSupportedException ("This platform is not supported");
- default:
- return new Win32IPGlobalProperties ();
- }
+ throw new NotImplementedException ();
+ }
+
+ public override IPEndPoint [] GetActiveUdpListeners ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override IcmpV4Statistics GetIcmpV4Statistics ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override IcmpV6Statistics GetIcmpV6Statistics ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override IPGlobalStatistics GetIPv4GlobalStatistics ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override IPGlobalStatistics GetIPv6GlobalStatistics ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override TcpStatistics GetTcpIPv4Statistics ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override TcpStatistics GetTcpIPv6Statistics ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override UdpStatistics GetUdpIPv4Statistics ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public override UdpStatistics GetUdpIPv6Statistics ()
+ {
+ throw new NotImplementedException ();
}
+ }
- public abstract TcpConnectionInformation [] GetActiveTcpConnections ();
- public abstract IPEndPoint [] GetActiveTcpListeners ();
- public abstract IPEndPoint [] GetActiveUdpListeners ();
- public abstract IcmpV4Statistics GetIcmpV4Statistics ();
- public abstract IcmpV6Statistics GetIcmpV6Statistics ();
- public abstract IPGlobalStatistics GetIPv4GlobalStatistics ();
- public abstract IPGlobalStatistics GetIPv6GlobalStatistics ();
- public abstract TcpStatistics GetTcpIPv4Statistics ();
- public abstract TcpStatistics GetTcpIPv6Statistics ();
- public abstract UdpStatistics GetUdpIPv4Statistics ();
- public abstract UdpStatistics GetUdpIPv6Statistics ();
-
- public abstract string DhcpScopeName { get; }
- public abstract string DomainName { get; }
- public abstract string HostName { get; }
- public abstract bool IsWinsProxy { get; }
- public abstract NetBiosNodeType NodeType { get; }
+#if MONODROID
+ sealed class AndroidIPGlobalProperties : UnixIPGlobalProperties
+ {
+ public override string DomainName {
+ get {
+ return String.Empty;
+ }
+ }
}
+#endif
// It expects /proc/net/snmp (or /usr/compat/linux/proc/net/snmp),
// formatted like:
// http://www.linuxdevcenter.com/linux/2000/11/16/example5.html
// http://www.linuxdevcenter.com/linux/2000/11/16/example2.html
- class MibIPGlobalProperties : IPGlobalProperties
+ class MibIPGlobalProperties : UnixIPGlobalProperties
{
- [DllImport ("libc")]
- static extern int gethostname ([MarshalAs (UnmanagedType.LPArray, SizeParamIndex = 1)] byte [] name, int len);
-
- [DllImport ("libc")]
- static extern int getdomainname ([MarshalAs (UnmanagedType.LPArray, SizeParamIndex = 1)] byte [] name, int len);
-
public const string ProcDir = "/proc";
public const string CompatProcDir = "/usr/compat/linux/proc";
IPEndPoint local = ToEndpoint (list [i] [1]);
IPEndPoint remote = ToEndpoint (list [i] [2]);
TcpState state = (TcpState) int.Parse (list [i] [3], NumberStyles.HexNumber);
- ret [i] = new TcpConnectionInformationImpl (local, remote, state);
+ ret [i] = new SystemTcpConnectionInformation (local, remote, state);
}
return ret;
}
{
return new MibUdpStatistics (GetProperties6 ("Udp6"));
}
-
- public override string DhcpScopeName {
- get { return String.Empty; }
- }
-
- public override string DomainName {
- get {
- byte [] bytes = new byte [256];
- if (getdomainname (bytes, 256) != 0)
- throw new NetworkInformationException ();
- int len = Array.IndexOf<byte> (bytes, 0);
- return Encoding.ASCII.GetString (bytes, 0, len < 0 ? 256 : len);
- }
- }
-
- public override string HostName {
- get {
- byte [] bytes = new byte [256];
- if (gethostname (bytes, 256) != 0)
- throw new NetworkInformationException ();
- int len = Array.IndexOf<byte> (bytes, 0);
- return Encoding.ASCII.GetString (bytes, 0, len < 0 ? 256 : len);
- }
- }
-
- public override bool IsWinsProxy {
- get { return false; } // no WINS
- }
-
- public override NetBiosNodeType NodeType {
- get { return NetBiosNodeType.Unknown; } // no NetBios
- }
}
+#if !MOBILE
class Win32IPGlobalProperties : IPGlobalProperties
{
public const int AF_INET = 2;
// PInvokes
- [DllImport ("Iphlpapi.dll")]
+ [DllImport ("iphlpapi.dll")]
static extern int GetTcpTable (byte [] pTcpTable, ref int pdwSize, bool bOrder);
- [DllImport ("Iphlpapi.dll")]
+ [DllImport ("iphlpapi.dll")]
static extern int GetTcp6Table (byte [] TcpTable, ref int SizePointer, bool Order);
- [DllImport ("Iphlpapi.dll")]
+ [DllImport ("iphlpapi.dll")]
static extern int GetUdpTable (byte [] pUdpTable, ref int pdwSize, bool bOrder);
- [DllImport ("Iphlpapi.dll")]
+ [DllImport ("iphlpapi.dll")]
static extern int GetUdp6Table (byte [] Udp6Table, ref int SizePointer, bool Order);
- [DllImport ("Iphlpapi.dll")]
+ [DllImport ("iphlpapi.dll")]
static extern int GetTcpStatisticsEx (out Win32_MIB_TCPSTATS pStats, int dwFamily);
- [DllImport ("Iphlpapi.dll")]
+ [DllImport ("iphlpapi.dll")]
static extern int GetUdpStatisticsEx (out Win32_MIB_UDPSTATS pStats, int dwFamily);
- [DllImport ("Iphlpapi.dll")]
+ [DllImport ("iphlpapi.dll")]
static extern int GetIcmpStatistics (out Win32_MIBICMPINFO pStats, int dwFamily);
- [DllImport ("Iphlpapi.dll")]
+ [DllImport ("iphlpapi.dll")]
static extern int GetIcmpStatisticsEx (out Win32_MIB_ICMP_EX pStats, int dwFamily);
- [DllImport ("Iphlpapi.dll")]
+ [DllImport ("iphlpapi.dll")]
static extern int GetIpStatisticsEx (out Win32_MIB_IPSTATS pStats, int dwFamily);
// Win32 structures
}
public TcpConnectionInformation TcpInfo {
- get { return new TcpConnectionInformationImpl (LocalEndPoint, RemoteEndPoint, State); }
+ get { return new SystemTcpConnectionInformation (LocalEndPoint, RemoteEndPoint, State); }
}
}
}
public TcpConnectionInformation TcpInfo {
- get { return new TcpConnectionInformationImpl (LocalEndPoint, RemoteEndPoint, State); }
+ get { return new SystemTcpConnectionInformation (LocalEndPoint, RemoteEndPoint, State); }
}
}
}
}
}
+#endif
}