Bug 1969 - System.Net.NetworkInformation.GetAllNetworkInterfaces() Fails
Summary: System.Net.NetworkInformation.GetAllNetworkInterfaces() Fails
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 5.0
Hardware: PC Windows
: High critical
Target Milestone: 6.0 (C6)
Assignee: Marek Habersack
URL:
: 1941 ()
Depends on:
Blocks:
 
Reported: 2011-11-09 09:22 UTC by Redth
Modified: 2015-11-13 15:53 UTC (History)
16 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Snippet from ADB Logcat (15.38 KB, image/png)
2011-11-09 09:22 UTC, Redth
Details
Test Case (490 bytes, text/plain)
2011-11-21 15:06 UTC, Jonathan Pobst
Details
ipaddress (30.43 KB, application/zip)
2015-04-22 17:44 UTC, Anuj Bhatia
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Redth 2011-11-09 09:22:37 UTC
Created attachment 856 [details]
Snippet from ADB Logcat

Unhandled Exception: System.EntryPointNotFoundException: getifaddrs

Can't use the .net network information classes
Comment 1 Jonathan Pryor 2011-11-17 17:06:35 UTC
*** Bug 1941 has been marked as a duplicate of this bug. ***
Comment 2 Jonathan Pobst 2011-11-21 15:06:55 UTC
Created attachment 922 [details]
Test Case

Test case from:
https://bugzilla.novell.com/show_bug.cgi?id=661106
Comment 3 Atsushi Eno 2012-09-24 05:50:36 UTC
getifaddrs() does not seem to exist in Android. https://groups.google.com/forum/?fromgroups=#!topic/android-ndk/3JIvD0PFaU4

-> Class Libraries (this is not really a runtime issue)
Comment 4 Jonathan Pryor 2012-09-24 15:34:39 UTC
getifaddres() _used_ to exist on Android, as a private API within libnativehelper.so:

    https://bugzilla.novell.com/show_bug.cgi?id=661106#c1

That said, the Galaxy Nexus version of libnativehelper.so does NOT contain the getifaddrs() export (of any form), so "simply" remapping things so that libnativehelper.so is used won't fix this issue.

We should probably add an assembly "cross-call" so that mscorlib.dll!System.Net.NetworkInformation.NetworkInterface calls into Mono.Android.dll so that we can use the Java APIs to query/return this information.
Comment 6 Curtis 2013-07-25 18:31:12 UTC
I am using an open source uPNP implementation.
http://opentools.homeip.net/dev-tools-for-upnp
 
In it, they use NetworkInterface.GetAllNetworkInterfaces().
 
My problem is that each of the returned interfaces has its OperationalStatus property set to 'Unknown'.
 
In Windows, all of these are set to 'Up' or 'Down'. However, when using Xamarin and running this same code on an iOS device, all of the interfaces have an OperationalStatus of 'Unknown'.
 
This is resulting in all of them being discarded because it is expecting at least one to be 'Up'. So, is there some method or something I need to do to get an accurate OperationStatus on these interfaces?
 
I have found ways around this, but I am trying to do some cross-platform development and don't want to special case the uPNP code for the iOS devices if at all possible.
Comment 8 Redth 2014-01-13 16:08:08 UTC
Yes, I simply worked around this with platform specific code.
Comment 9 Infologique Innovations inc. 2014-07-10 08:21:31 UTC
We are in the same situation as Curtis.  Unable to get OperationalStatus property (always "Unknown").
Comment 10 Marek Habersack 2014-07-10 08:57:35 UTC
This issue is already fixed in our repositories, but it's pending peer review and inclusion in the released Xamarin.Android version. I'll close the bug once the fix is in the build pipeline on its way to release.
Comment 11 Marek Habersack 2014-07-30 18:24:47 UTC
Fixed in the current monodroid master
Comment 12 Zack Gramana 2014-09-17 19:42:38 UTC
Wondering if this is just not yet in stable, or is a regression (never noticed this until the recent X.A update). On Android 4.2 && 4.4.2:

    `var ifs = NetworkInterface.GetAllNetworkInterfaces();`

results in:

{System.EntryPointNotFoundException: getifaddrs
  at (wrapper managed-to-native) System.Net.NetworkInformation.LinuxNetworkInterface:getifaddrs (intptr&)
  at System.Net.NetworkInformation.LinuxNetworkInterface.ImplGetAllNetworkInterfaces () [0x00000] in <filename unknown>:0 
  at System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces () [0x00000] in <filename unknown>:0 }
	Data: Count=0
	HResult: -2146233053
	HelpLink: (null)
	InnerException: (null)
	Message (System.Exception): "getifaddrs"
	Message (System.TypeLoadException): "getifaddrs"
	Source: "System"
	StackTrace: "  at (wrapper managed-to-native) System.Net.NetworkInformation.LinuxNetworkInterface:getifaddrs (intptr&)\n  at System.Net.NetworkInformation.LinuxNetworkInterface.ImplGetAllNetworkInterfaces () [0x00000] in <filename unknown>:0 \n  at System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces () [0x00000] in <filename unknown>:0 "
	TargetSite: {System.Net.NetworkInformation.NetworkInterface[] ImplGetAllNetworkInterfaces()}
	TypeName: ""
	Static members: 
	Non-public members: 

Deets:

Xamarin Studio
Version 5.3 (build 441)
Installation UUID: 47f03afd-7c04-4aec-8195-1b1617231ab4
Runtime:
	Mono 3.8.0 ((no/45d0ba1)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 308000009

Xamarin.Android
Version: 4.16.0 (Business Edition)
Android SDK: /Users/zgramana/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

Build Information
Release ID: 503000441
Git revision: befb6aa1176d37a5f678f4274f340a0159091b7a
Build date: 2014-09-08 17:57:02-04
Xamarin addins: 6dc7c388e31fdfc8014689839d37de0d4622435c

Operating System
Mac OS X 10.9.4
Darwin zmacbook.att.net 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Comment 13 Zack Gramana 2014-09-17 19:51:14 UTC
In addition, NetworkChange.NetworkAvailabilityChanged invoker will trigger the above exception on Android at this location: https://github.com/mono/mono/blob/effa4c07ba850bedbe1ff54b2a5df281c058ebcb/mcs/class/System/System.Net.NetworkInformation/NetworkChange.cs#L405
Comment 14 Marek Habersack 2014-09-18 08:34:12 UTC
Zack, the fix is not in Android 4.16 indeed.
Comment 15 Zack Gramana 2014-09-18 20:36:03 UTC
Thanks Marek! #ifdefs it is! : )
Comment 20 Anuj Bhatia 2015-04-22 17:44:39 UTC
Created attachment 10873 [details]
ipaddress
Comment 21 Anuj Bhatia 2015-04-22 17:44:59 UTC
ram, attachment provided. thanks.
Comment 22 Jonathan Pryor 2015-04-22 18:06:24 UTC
@Anuj: On which device does it fail? Attachment #10873 [details] works for me on a Nexus 5.
Comment 23 Anuj Bhatia 2015-04-22 18:24:38 UTC
@JonP: Samsung SM-G900H
Comment 24 Jon Goldberger [MSFT] 2015-04-22 20:40:26 UTC
I was _not_ able to reproduce the issue on a Samsung Galaxy Tab 2 running 4.2.2.
Comment 26 Marek Habersack 2015-05-04 13:00:19 UTC
Managed to repro on Nexus 9 using the code from comment 20, working on the fix now
Comment 27 Marek Habersack 2015-05-04 18:26:15 UTC
Fixed in master, commit 553f1210588991af80c16889c391fad30824266f
Comment 28 Peter Collins 2015-11-13 15:53:46 UTC
I could repro the hang mentioned in Comment #25 on a GS5 and Nexus 9, and confirm that this  hang is now fixed in monodroid/cycle6/3efa14c4.