') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); [Android] NetworkInterface.GetAllNetworkInterfaces() returns strange values on Android 11 + IPv6 · Issue #6973 · dotnet/android · GitHub
Skip to content

[Android] NetworkInterface.GetAllNetworkInterfaces() returns strange values on Android 11 + IPv6 #6973

Description

@Eilon

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:
ipv6-28

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:
ipv4-31

If IPv6 is enabled in the router, NetworkInterfaceType and OperationalStatus values are even worse.
ipv6-31

Steps to Reproduce

  1. Create a new Maui app (VS 2022 17.2 Preview 5)
  2. Replace MainPage with the files below

MainPage.xaml.cs

namespace MauiApp1;
using System.Net.NetworkInformation;
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
LoadNics();
BindingContext = this;
}
public Nic[] Nics { get; set; }
private void LoadNics()
{
var nics = new List<Nic>();
var ifs = NetworkInterface.GetAllNetworkInterfaces();
foreach (var i in ifs)
{
var n = new Nic
{
Name = i.Name,
Description = i.Description,
Status = i.OperationalStatus,
Type = i.NetworkInterfaceType
};
if (i.Supports(NetworkInterfaceComponent.IPv4))
n.Supports += "IPv4 ";
if (i.Supports(NetworkInterfaceComponent.IPv6))
n.Supports += "IPv6 ";
foreach (var a in i.GetIPProperties().UnicastAddresses)
{
if (a.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
n.IPv6Addresses += a.Address.ToString() + " ";
if (a.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
n.IPv4Addresses += a.Address.ToString() + " ";
}
nics.Add(n);
}
Nics = nics.ToArray();
}
}
public class Nic
{
public string Name { get; set; }
public string Description { get; set; }
public OperationalStatus Status { get; set; }
public NetworkInterfaceType Type { get; set; }
public string Supports { get; set;}
public string IPv4Addresses { get; set; }
public string IPv6Addresses { get; set; }
}

MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiApp1.MainPage">
<ListView ItemsSource="{Binding Nics, Mode=OneWay}" SelectionMode="None" RowHeight="{OnPlatform Android=140}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid ColumnSpacing="8">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0" Text="Name" FontAttributes="Bold" FontSize="Subtitle"/>
<Label Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="2" Text="{Binding Name}" FontSize="Subtitle"/>
<Label Grid.Column="1" Grid.Row="1" Text="Description" />
<Label Grid.Column="2" Grid.Row="1" Text="{Binding Description}" />
<Label Grid.Column="1" Grid.Row="2" Text="Status" />
<Label Grid.Column="2" Grid.Row="2" Text="{Binding Status}" />
<Label Grid.Column="1" Grid.Row="3" Text="Type" />
<Label Grid.Column="2" Grid.Row="3" Text="{Binding Type}" />
<Label Grid.Column="1" Grid.Row="4" Text="Supports" />
<Label Grid.Column="2" Grid.Row="4" Text="{Binding Supports}" />
<Label Grid.Column="1" Grid.Row="5" Text="IPv4Addresses" />
<Label Grid.Column="2" Grid.Row="5" Text="{Binding IPv4Addresses}" />
<Label Grid.Column="1" Grid.Row="6" Text="IPv6Addresses" />
<Label Grid.Column="2" Grid.Row="6" Text="{Binding IPv6Addresses}" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>

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

Metadata

Metadata

Assignees

Labels

Area: Mono RuntimeMono-related issues: BCL bugs, AOT issues, etc.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions