implement GetScopeId() on Linux (#1038)
authorTomas Weinfurt <tweinfurt@yahoo.com>
Mon, 6 Jan 2020 17:17:50 +0000 (09:17 -0800)
committerStephen Toub <stoub@microsoft.com>
Mon, 6 Jan 2020 17:17:50 +0000 (12:17 -0500)
src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/LinuxIPv6InterfaceProperties.cs
src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/IPInterfacePropertiesTest_Linux.cs

index f2bb3ff..6482e6e 100644 (file)
@@ -20,7 +20,13 @@ namespace System.Net.NetworkInformation
 
         public override long GetScopeId(ScopeLevel scopeLevel)
         {
-            throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform);
+            if (scopeLevel == ScopeLevel.None || scopeLevel == ScopeLevel.Interface ||
+                scopeLevel == ScopeLevel.Link || scopeLevel == ScopeLevel.Subnet)
+            {
+                return _linuxNetworkInterface.Index;
+            }
+
+            return 0;
         }
     }
 }
index 72f2346..8df14a8 100644 (file)
@@ -27,8 +27,10 @@ namespace System.Net.NetworkInformation.Tests
             foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
             {
                 _log.WriteLine("Nic: " + nic.Name);
+                _log.WriteLine("- Speed:" + nic.Speed);
                 _log.WriteLine("- Supports IPv4: " + nic.Supports(NetworkInterfaceComponent.IPv4));
                 _log.WriteLine("- Supports IPv6: " + nic.Supports(NetworkInterfaceComponent.IPv6));
+                Assert.False(nic.IsReceiveOnly);
 
                 IPInterfaceProperties ipProperties = nic.GetIPProperties();
 
@@ -149,7 +151,7 @@ namespace System.Net.NetworkInformation.Tests
 
                 _log.WriteLine("Index: " + ipv6Properties.Index);
                 _log.WriteLine("Mtu: " + ipv6Properties.Mtu);
-                Assert.Throws<PlatformNotSupportedException>(() => ipv6Properties.GetScopeId(ScopeLevel.Link));
+                _log.WriteLine("Scope: " + ipv6Properties.GetScopeId(ScopeLevel.Link));
             }
         }
 
@@ -175,7 +177,7 @@ namespace System.Net.NetworkInformation.Tests
                 Array values = Enum.GetValues(typeof(ScopeLevel));
                 foreach (ScopeLevel level in values)
                 {
-                    Assert.Throws<PlatformNotSupportedException>(() => ipv6Properties.GetScopeId(level));
+                    _log.WriteLine("-- Level: " + level + "; " + ipv6Properties.GetScopeId(level));
                 }
             }
         }