5a67f249f90222cdc22f11cc45662a82a6f2bfb0
[mono.git] / mcs / class / referencesource / System / net / System / Net / NetworkInformation / IPGlobalProperties.cs
1
2 using System;
3 using System.Net.Sockets;
4 using System.Net;
5 using System.Threading.Tasks;
6 using System.Security.Permissions;
7 using System.Diagnostics.CodeAnalysis;
8 using System.IO;
9
10 namespace System.Net.NetworkInformation
11 {
12
13     public abstract class IPGlobalProperties
14     {
15         public static IPGlobalProperties GetIPGlobalProperties()
16         {
17 #if MONODROID
18             return new AndroidIPGlobalProperties ();
19 #elif MONOTOUCH || XAMMAC || MOBILE_STATIC
20             return new UnixIPGlobalProperties ();
21 #elif MONO
22             switch (Environment.OSVersion.Platform) {
23             case PlatformID.Unix:
24                 MibIPGlobalProperties impl = null;
25                 if (Directory.Exists (MibIPGlobalProperties.ProcDir)) {
26                     impl = new MibIPGlobalProperties (MibIPGlobalProperties.ProcDir);
27                     if (File.Exists (impl.StatisticsFile))
28                         return impl;
29                 }
30                 if (Directory.Exists (MibIPGlobalProperties.CompatProcDir)) {
31                     impl = new MibIPGlobalProperties (MibIPGlobalProperties.CompatProcDir);
32                     if (File.Exists (impl.StatisticsFile))
33                         return impl;
34                 }
35                 return new UnixIPGlobalProperties ();
36             default:
37                 return new Win32IPGlobalProperties ();
38             }
39 #else          
40             (new NetworkInformationPermission(NetworkInformationAccess.Read)).Demand();
41             return new SystemIPGlobalProperties();
42 #endif
43         }
44
45         internal static IPGlobalProperties InternalGetIPGlobalProperties()
46         {
47 #if MONO
48             return GetIPGlobalProperties();
49 #else
50             return new SystemIPGlobalProperties();
51 #endif
52         }
53
54         /// Gets the Active Udp Listeners on this machine
55         public abstract IPEndPoint[] GetActiveUdpListeners();
56                 
57         /// Gets the Active Tcp Listeners on this machine
58         public abstract IPEndPoint[] GetActiveTcpListeners ();
59
60         /// Gets the Active Udp Listeners on this machine
61         public abstract TcpConnectionInformation[] GetActiveTcpConnections();
62
63         /// Gets the Dynamic Host Configuration Protocol (DHCP) scope name.
64         public abstract string DhcpScopeName {get;}
65
66         /// Gets the domain in which the local computer is registered.
67         
68         public abstract string DomainName {get;}
69
70         /// Gets the host name for the local computer.
71         
72         public abstract string HostName {get;}
73
74         /// Gets a bool value that specifies whether the local computer is acting as a Windows Internet Name Service (WINS) proxy.
75         public abstract bool IsWinsProxy {get;}
76
77         /// Gets the Network Basic Input/Output System (NetBIOS) node type of the local computer.
78         public abstract NetBiosNodeType NodeType{get;}
79         
80
81         public abstract TcpStatistics GetTcpIPv4Statistics();
82
83         public abstract TcpStatistics GetTcpIPv6Statistics();
84
85         /// Provides Internet Control Message Protocol (ICMP) version 4 statistical data for the local computer.
86         /// Provides User Datagram Protocol (UDP) statistical data for the local computer.
87         
88         public abstract UdpStatistics GetUdpIPv4Statistics();
89         public abstract UdpStatistics GetUdpIPv6Statistics();
90         
91         /// Provides Internet Control Message Protocol (ICMP) version 4 statistical data for the local computer.
92         
93         public abstract IcmpV4Statistics GetIcmpV4Statistics();
94
95         /// Provides Internet Control Message Protocol (ICMP) version 6 statistical data for the local computer.
96         
97         public abstract IcmpV6Statistics GetIcmpV6Statistics();    
98
99         /// Provides Internet Protocol (IP) statistical data for the local computer.
100         public abstract IPGlobalStatistics GetIPv4GlobalStatistics();    
101         public abstract IPGlobalStatistics GetIPv6GlobalStatistics();
102
103         /// Returns a list of all unicast IP addresses after ensuring they are all stable
104         public virtual UnicastIPAddressInformationCollection GetUnicastAddresses()
105         {
106             throw ExceptionHelper.MethodNotImplementedException;
107         }
108
109         public virtual IAsyncResult BeginGetUnicastAddresses(AsyncCallback callback, object state)
110         {
111             throw ExceptionHelper.MethodNotImplementedException;
112         }
113
114         public virtual UnicastIPAddressInformationCollection EndGetUnicastAddresses(IAsyncResult asyncResult)
115         {
116             throw ExceptionHelper.MethodNotImplementedException;
117         }
118
119         //************* Task-based async public methods *************************
120         [HostProtection(ExternalThreading = true)]
121         [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Unicast")]
122         public virtual Task<UnicastIPAddressInformationCollection> GetUnicastAddressesAsync()
123         {
124             return Task<UnicastIPAddressInformationCollection>.Factory.FromAsync(BeginGetUnicastAddresses, EndGetUnicastAddresses, null);
125         }
126
127     }    
128 }
129