-
Notifications
You must be signed in to change notification settings - Fork 533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] NetworkInterface.GetAllNetworkInterfaces() returns strange values on Android 11 + IPv6 #6973
[Android] NetworkInterface.GetAllNetworkInterfaces() returns strange values on Android 11 + IPv6 #6973
Comments
Issue moved from dotnet/maui#6649
From @v-longmin on Friday, April 29, 2022 7:51:12 AM Verified repro on Android 12.0 with VS 17.3.0 Preview 1.0 [32427.455.main]. Repro with above project. |
Issue moved from dotnet/maui#6649
From @Eilon on Friday, April 29, 2022 5:41:03 PM @jonathanpeppers - should this go to Xamarin Android? Or dotnet/runtime? |
Issue moved from dotnet/maui#6649
From @jonathanpeppers on Friday, April 29, 2022 6:26:18 PM I would send this to xamarin/xamarin-android, thanks. We have some code there that passes these values to the BCL. |
@jonathanpeppers @grendello It seems that this works normally on some older phones with Android 8.0 but returns bad values on newer versions of Android. I hope that helps. Any idea when this might be fixed? |
@philipag I'm afraid it might be hard to fix. Newer Android versions clamped down on the information available to "untrusted" apps and some information might be available only via the relevant Java API (you can access it via our bindings, of course). Please follow the steps below and attach the resulting $ adb shell setprop debug.mono.log default,netlink
$ adb logcat -G 16M
$ adb logcat -c
# Run the app here
$ adb logcat -d > logcat.txt |
@grendello Here is the resulting log. The app name is "testapp". |
@philipag thanks! Unfortunately, it seems our netlink code isn't used in your app. The only netlink messages I see are:
Which looks like some kind of throttling (?), possibly triggered by the new network interface enumeration code in dotnet runtime. @simonrozsival would you mind taking a look? |
I can confirm that var ifaces = Java.Net.NetworkInterface.NetworkInterfaces;
while (ifaces.HasMoreElements)
{
var iface = ifaces.NextElement().JavaCast<Java.Net.NetworkInterface>();
// ...
} .NET internally uses the libc |
@simonrozsival XA has an implementation of |
@grendello I'll give it a try. |
The network interfaces' information is accessible through netlink so I ported the XA implementation into dotnet/runtime. |
In recent Android versions the data returned by getifaddrs is invalid and doesn't allow us to implement System.Net.NetworkInformation.GetAllNetworkInterfaces(). It's possible to reimplement getifaddrs using Netlink and there's already an existing implementation in Xamarin.Android. Fixes dotnet/android#6973 Ref #62780 Ref #51303
Issue moved from dotnet/maui#6649
From @MartinRothschink on Friday, April 29, 2022 7:05:05 AM
Description
All tests have been done on a Xaomi Pad 5 (physical device, Android 11).
If target sdk is set to < 30, the values returned by NetworkInterface.GetAllNetworkInterfaces() seem valid:
If target sdk is set to 31, the values returned by NetworkInterface.GetAllNetworkInterfaces() are outside of the enum ranges and name/description are empty. This screen shot shows the situation if IPv6 is not enabled in the router:
If IPv6 is enabled in the router, NetworkInterfaceType and OperationalStatus values are even worse.
Steps to Reproduce
MainPage.xaml.cs
MainPage.xaml
Version with bug
Release Candidate 2 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 10/11 (target sdk >= 30)
Did you find any workaround?
Currently I have to ignore the values for OperationalStatus and use the interface with valid UnicastAddresses.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: