Merge pull request #4248 from Unity-Technologies/boehm-gc-alloc-fixed
[mono.git] / mcs / class / System / System.Net.NetworkInformation / IPv4InterfaceProperties.cs
index 8f1ddbbaef57b1df6baf27af371b750a07c4305e..86fba917ab9079eb6233cc33681d9b15a66960ef 100644 (file)
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-#if NET_2_0
 using System.IO;
 using System.Runtime.InteropServices;
 
 namespace System.Net.NetworkInformation {
-       public abstract class IPv4InterfaceProperties {
-               protected IPv4InterfaceProperties ()
-               {
-               }
-
-               public abstract int Index { get; }
-               public abstract bool IsAutomaticPrivateAddressingActive { get; }
-               public abstract bool IsAutomaticPrivateAddressingEnabled { get; }
-               public abstract bool IsDhcpEnabled { get; }
-               public abstract bool IsForwardingEnabled { get; }
-               public abstract int Mtu { get; }
-               public abstract bool UsesWins { get; }
-       }
-
-       sealed class LinuxIPv4InterfaceProperties : IPv4InterfaceProperties
+       abstract class UnixIPv4InterfaceProperties : IPv4InterfaceProperties
        {
-               LinuxNetworkInterface iface;
+               protected UnixNetworkInterface iface;
                
-               public LinuxIPv4InterfaceProperties (LinuxNetworkInterface iface)
+               public UnixIPv4InterfaceProperties (UnixNetworkInterface iface)
                {
                        this.iface = iface;
                }
                
                public override int Index {
-                       get { return LinuxNetworkInterface.IfNameToIndex (iface.Name); }
+                       get { return iface.NameIndex; }
                }
 
                // TODO: how to discover that?
@@ -74,12 +59,24 @@ namespace System.Net.NetworkInformation {
                        get { return false; }
                }
        
+               public override bool UsesWins {
+                       get { return false; }
+               }
+       }
+       
+       sealed class LinuxIPv4InterfaceProperties : UnixIPv4InterfaceProperties
+       {
+               public LinuxIPv4InterfaceProperties (LinuxNetworkInterface iface)
+                       : base (iface)
+               {
+               }
+               
                public override bool IsForwardingEnabled {
                        get {
                                string iface_path = "/proc/sys/net/ipv4/conf/" + iface.Name + "/forwarding";
 
                                if (File.Exists (iface_path)) {
-                                       string val = NetworkInterface.ReadLine (iface_path);
+                                       string val = LinuxNetworkInterface.ReadLine (iface_path);
 
                                        return val != "0";
                                }
@@ -87,13 +84,14 @@ namespace System.Net.NetworkInformation {
                                return false;
                        }
                }
+
                public override int Mtu {
                        get {
-                               string iface_path = iface.IfacePath + "mtu";
+                               string iface_path = (iface as LinuxNetworkInterface).IfacePath + "mtu";
                                int ret = 0;
 
                                if (File.Exists (iface_path)) {
-                                       string val = NetworkInterface.ReadLine (iface_path);
+                                       string val = LinuxNetworkInterface.ReadLine (iface_path);
                                        
                                        try {
                                                ret = Int32.Parse (val);
@@ -105,12 +103,27 @@ namespace System.Net.NetworkInformation {
                                                
                        }
                }
-       
-               public override bool UsesWins {
+       }
+
+       sealed class MacOsIPv4InterfaceProperties : UnixIPv4InterfaceProperties
+       {
+               public MacOsIPv4InterfaceProperties (MacOsNetworkInterface iface)
+                       : base (iface)
+               {
+               }
+
+               // dummy
+               public override bool IsForwardingEnabled {
                        get { return false; }
                }
+
+               // dummy
+               public override int Mtu {
+                       get { return 0; }
+               }
        }
        
+#if WIN_PLATFORM
        sealed class Win32IPv4InterfaceProperties : IPv4InterfaceProperties
        {
                [DllImport ("iphlpapi.dll")]
@@ -152,7 +165,7 @@ namespace System.Net.NetworkInformation {
 
                public override bool IsForwardingEnabled {
                        // Is it the right answer? In Vista there is MIB_IPINTERFACEROW.ForwardingEnabled, but not in former versions.
-                       get { return Win32_FIXED_INFO.Instance.EnableRouting != 0; }
+                       get { return Win32NetworkInterface.FixedInfo.EnableRouting != 0; }
                }
 
                public override int Mtu {
@@ -172,6 +185,6 @@ namespace System.Net.NetworkInformation {
                public IntPtr CurrentDnsServer; // to Win32_IP_ADDR_STRING
                public Win32_IP_ADDR_STRING DnsServerList;
        }
-}
 #endif
+}