diff --git a/src/Mono.Android/Test/System.Net/NetworkInterfaces.cs b/src/Mono.Android/Test/System.Net/NetworkInterfaces.cs index 17176eb3123..cb0c1eecb49 100644 --- a/src/Mono.Android/Test/System.Net/NetworkInterfaces.cs +++ b/src/Mono.Android/Test/System.Net/NetworkInterfaces.cs @@ -170,7 +170,7 @@ bool IsInterfaceUp (MNetworkInterface inf) default: // Android considers 'lo' to be always up - return inf.NetworkInterfaceType == NetworkInterfaceType.Loopback; + return IsLoopbackInterface (inf); } } @@ -188,9 +188,10 @@ byte[] GetHardwareAddress (MNetworkInterface inf) var ret = new List (); foreach (MNetworkInterface inf in interfaces) { + Console.WriteLine ($"inf: {inf} (name: {inf.Name}; type: {inf.NetworkInterfaceType})"); ret.Add (new InterfaceInfo { Name = inf.Name, - IsLoopback = inf.NetworkInterfaceType == NetworkInterfaceType.Loopback, + IsLoopback = IsLoopbackInterface (inf), IsUp = IsInterfaceUp (inf), HardwareAddress = GetHardwareAddress (inf), Addresses = CollectAddresses (inf) @@ -220,5 +221,12 @@ byte[] GetHardwareAddress (MNetworkInterface inf) return ret; } + + static bool IsLoopbackInterface (MNetworkInterface inf) + { + // Android 30 will not tell us the interface type if the app targets API 30, we need to look at the + // name then. + return inf.NetworkInterfaceType == NetworkInterfaceType.Loopback || String.Compare ("lo", inf.Name, StringComparison.OrdinalIgnoreCase) == 0; + } } }