46 Commits
Author SHA1 Message Date
Johan Lorensson 99729bc0b3 Restructure NetworkInformation classes to avoid full AOT compile errors. (#9432)
When doing full AOT of System.dll on Windows and other platforms building
runtime without HOST_DARWIN or HOST_BSD we will get an ugly error,
but compilation will still succeed leaving the user confused around the result.

The following error is printed:

--------------------------------------

cant resolve internal call to
"System.Net.NetworkInformation.MacOsIPInterfaceProperties::ParseRouteInfo_internal"
(tested without signature also)

Your mono runtime and class libraries are out of sync.
The out of sync library is: C:\github\mono\msvc\build\fullaot\winaot\system.dll

When you update one from git you need to update, compile and install
the other too.
Do not report this as a bug unless you're sure you have updated correctly:
you probably have a broken mono install.
If you see other errors or faults after this message they are probably related
and you need to fix your mono install first.
cant resolve internal call to
"System.Net.NetworkInformation.MacOsIPInterfaceProperties::ParseRouteInfo_internal"
(tested without signature also)

Your mono runtime and class libraries are out of sync.
The out of sync library is: C:\github\mono\msvc\build\fullaot\winaot\system.dll

When you update one from git you need to update, compile and install
the other too.
Do not report this as a bug unless you're sure you have updated correctly:
you probably have a broken mono install.
If you see other errors or faults after this message they are probably related
and you need to fix your mono install first.

--------------------------------------

The problem is that MacOs/BSD specific NetworkInformation classes are build into
System.dll on all platforms. One way to solve this is to start splitting the different
platforms specific implementations into different source files so we could start to
include/exclude sources per platform and profile in a nicer way instead of just
ifdef:ing inside current source files. This strategy also matches how corefx have
structured their NetworkInformation sources making it easier in the future to bring
mono’s NetworkInformation implementation closer to corefx. This PR implements this strategy.

Due to the fact that we don’t have platform specific configs for all profiles
(like basic and build) we can’t exclude all platform specific sources from
common.sources in System and move them to platform specific profiles. Ones we
have that full capability we could drop the #if WIN_PLATFORM in all the Win32*
files and exclude them from common.sources and only include them in the corresponding
win32 specific profiles. The same strategy could then be applied for other platform
specific profiles as well.

For Windows specific profiles, like win32_net_4_x_System.dll and winaot_System.dll we
use the .exclude.sources to remove the unix/linux/macos NetworkInformation sources,
so with this commit we will get a System.dll that only includes the Win32 specific
NetworkInformation classes and none of the unix/linux/macos, this will make sure the
compile error during full AOT won’t happen since there is no classes left including
the icall not available on a Windows mono runtime.

Other platforms will have the same classes in System.dll as before for now
but the source code is now structured making it possible to include/exclude platform
specific source files for other platforms as well, when needed.
2018-07-07 02:04:50 +02:00
Mauro Giusti 39af47841f Console.Error.WriteLine in System.Net.NetworkInformation
Console.Error.WriteLine ("Got a bad hardware address length for an AF_PACKET {0} {1}",...

This Console.WriteLine interferes with Apache Storm that reads from the console I/O.

See bug: https://bugzilla.xamarin.com/show_bug.cgi?id=57887
2017-06-30 09:13:31 -07:00
Andi McClure bebbf5134d Style fixes for PR feedback 2017-03-31 11:53:53 -04:00
Andi McClure 2ffb9a35a7 Combined cherrypick of changes between mono-4.8.0-branch and orbis-branch-30
ORBIS #ifdefs in BCL, exclude several files and assembly directories
from the orbis build, HAVE_LOCALTIME_R define in C.
2017-03-30 17:57:00 -04:00
Henric Müller 5a28b08795 Changing Win32_IP_ADAPTER_INFO to struct to work on AOT builds 2017-01-25 16:34:55 +01:00
Henric Müller 2c84763a1a Fixes in NetworkInformation for winaot profile
* Enabling windows specific code for winaot profile
which were disabled with MOBILE define.
* Making sure Win32_FIXED_INFO struct can get marshalled
correctly for AOT builds.
2017-01-25 16:33:24 +01:00
Marek Safar 95b0698304 [System] Clean up some warnings 2016-10-25 14:28:35 +02:00
Marek Habersack c439b67887 With Android 7.0 (Nougat) it is no longer possible to read some
information about network interfaces from the /sys filesystem. Google
placed restrictions on two files used by the Mono BCL to read
information about the interface:

      /sys/class/net/[DEVICE]/flags
      /sys/class/net/[DEVICE]/operstate

The information we used to read from `flags` let us determine whether
the interface supports multicast and the `operstate` file provided us
with detailed information on the current device state.

Additionally, it is now impossible to read the hardware MAC address used
by any interface. This bit of information is also unavailable when using
the Java APIs and therefore applications running on devices with API
24 (and possibly newer) will not be able to access this information.

More details about the issue are available from the upstream Android
bug:

      https://code.google.com/p/android/issues/detail?id=205565

In order to obtain the required information, we now need to use the Java
APIs on devices with API 24+ and this commit implements the backend to
retrieve this information. It is done in C in order to avoid overhead of
creating mirror .NET objects when calling Java, thus saving time and
memory during an operation which may be performed by some applications
quite frequently.

This patch implements code that calls into the Xamarin.Android
runtime when runnin under API24 or newer to obtain the information.

Part of fix for https://bugzilla.xamarin.com/show_bug.cgi?id=44296
2016-10-17 22:29:49 +02:00
Henric Müller 2cb3807146 Implementation of GetLoopbackInterfaceIndex on Windows 2016-09-21 13:54:34 +02:00
Marek Safar d3b0701f62 [System] Common NetworkInformation code from referencesource 2016-05-18 16:02:38 +02:00
Alexander Kyte d6d786c07a [bcl] Fix Win32 network api exclusion on non-monodroid mobile 2016-01-05 11:38:06 -05:00
alex-skiffin 1ebbfe8740 [NetworkInterface] Implement IPv4Mask property on Linux.
This change is released under the MIT license.
2015-12-01 09:37:40 +05:00
Sebastien Pouliot b14d33150a [system][monodroid] Remove reference to Win32NetworkInterfaceAPI (as the type was removed from the profile earlier) 2015-11-24 09:38:07 -05:00
Sebastien Pouliot 9ea2f50a2a [System] Remove internal Win32* classes from mobile builds
This reduce the size of System.dll and also removes some Win32 specific
p/invokes.

They cause native linking issues for tvOS as Xcode 7.1 does not allow
`-u` in bitcode-enabled builds so we have to call directly the symbols
and it must exists at (native) link time.
2015-11-20 11:57:48 -05:00
Marek Safar 2c9ee7f2d5 [system] Implements IPv4Mask property on mac. Fixes #30880 2015-06-18 17:25:11 +02:00
Marek Safar d13b92edb1 [System] Extract NetworkInterface factory and implement LoopbackInterfaceIndex for more platforms 2015-01-20 15:04:32 +01:00
Ben Woods ba998de3c9 Freebsd to use Mac NetworkInterface code instead of Linux NetworkInterface code 2014-11-06 17:27:36 +08:00
Marek Habersack 59258ea3f0 Turns out some devices can have network interfaces without names.
If we encounter such a device we assign it an empty name followed by index number, so that we can
put any number of such devices in the dictionary and report them to the user.

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=21741
2014-07-31 19:45:05 -04:00
Marek Habersack 303e42b130 Implement the Mono side of Android support for NetworkInterface.GetAllNetworkInterfaces ()
Added code to call Xamarin.Android internal implementation of getifaddrs/freeifaddrs to provide us
with the required information to fulfill the request.

Added a handful of Linux ARP hardware IDs which are considered to be tunnel devices and which may occur
on Android devices.

Part of fix for https://bugzilla.xamarin.com/show_bug.cgi?id=1969
2014-07-30 18:22:33 -04:00
Christian Hüning 5e43e5d6db - ADDED: Support to read out Interface flags on OS X
- ADDED: Implemented NetworkInterface property "OperationalStatus" to be UP, in case the IFF_UP flag is set
- ADDED: Implemented NetworkInterface property "SupportsMulticast" to be true, in case the IFF_MULTICAST flag is set

This change is released under the MIT license.
2014-06-05 14:09:11 +02:00
Miguel de Icaza 705da187cf [System] Fix build warnings 2014-05-04 17:15:18 -04:00
Sebastien Pouliot d8bdd1f209 Do not bring Win32 or Linux specific code for iOS NetworkInterface 2013-05-13 11:10:11 -04:00
Rolf Bjarne Kvinge 31f07a71fa Marshal sockaddrdl manually, since it contains a variable-length byte array. Fixes #7329. 2012-09-21 02:06:40 +02:00
Miguel de Icaza f48ceb9860 [System] Removal of the NET_2_0 in the source code
Modulo the GUID in the assembly and the GUID embedded in some
field initializers that use the assembly GUID for their name, the
assemblies are idential before and after the patch.
2012-06-02 13:16:40 -04:00
Jonathan Pryor f12dacdc78 [System] Fix MacOsNetworkInterface.ImplGetAllNetworkInterfaces()
On my (cursed?) MacBook Pro, calling
System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
results in an exception:

	System.ArgumentException: length
		at System.Array.Copy (System.Array sourceArray, Int32 sourceIndex, System.Array destinationArray, Int32 destinationIndex, Int32 length) [0x00000] in <filename unknown>:0
		at System.Net.NetworkInformation.MacOsNetworkInterface.ImplGetAllNetworkInterfaces () [0x00000] in <filename unknown>:0
		at System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces () [0x00000] in <filename unknown>:0

Some printfs later, and we see why:

	Array.Copy(array.Length=12, 3, array.Length=0, 0, 0)
	Array.Copy(array.Length=12, 4, array.Length=0, 0, 0)
	Array.Copy(array.Length=12, 4, array.Length=0, 0, 0)
	Array.Copy(array.Length=12, 3, array.Length=6, 0, 6)
	Array.Copy(array.Length=12, 3, array.Length=6, 0, 6)
	Array.Copy(array.Length=12, 3, array.Length=8, 0, 4)
	Array.Copy(array.Length=12, 4, array.Length=6, 0, 6)
	Array.Copy(array.Length=12, 8, array.Length=6, 0, 6)
	# BOOM!

(Apparently I have 8 interfaces: lo0, gif0, stf0, en0, en1, fw0, p2p0,
and vboxnet0.)

The problem is readily obvious: we're trying to read 6 bytes of data
when only 4 are available, and Array.Copy() complains appropriately.

The fix -- which looks to almost contradict a02076ba -- is to use
`sockaddrdl.sdl_data.Length - sockaddrdl.sdl_nlen` instead of
`sockaddrdl.sdl_data.Length - macAddress.Length` (or sdl_alen).
sdl_nlen is the offset into the source sockaddrdl.sdl_data array, and
in this case sockaddrdl.sdl_alen (the length of the destination
macAddress) isn't the same as sockaddrdl.sdl_nlen, hence the breakage.
2012-04-05 15:39:45 -04:00
Gonzalo Paniagua Javier c89f1eb275 Fix MAC address for Mac/iOS
The position of the first byte to copy was wrong.
	Fixes bug #2012.
2011-12-13 10:24:30 -05:00
Jeffrey Stedfast 7715de7ad9 Implemented a shared way to do MacOSX detection in System.dll 2011-07-05 17:52:25 -04:00
Gonzalo Paniagua Javier 75d42f19f9 [NetworkInformation] Support network IP/status events
Add support for the events in NetworkChanged (linux-only).
2011-03-27 18:50:35 -04:00
Miguel de Icaza f6472ef0da [594642] System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces fix for MacOS X 2011-02-19 11:05:29 -05:00
Atsushi Eno ecd96c968a Fix NetworkInterface marshaling size on OSX and avoid crash. 2010-09-06 16:29:26 +09:00
Gonzalo Paniagua Javier 1ae7d82d80 2010-07-05 Gonzalo Paniagua Javier <[email protected]>
* NetworkInterface.cs: avoid endless loop when a bad length is
	received for AF_PACKET. Fixes bug #601783.


svn path=/trunk/mcs/; revision=159921
2010-07-05 18:30:41 +00:00
Miguel de Icaza f47e5fe6a6 2010-03-20 Miguel de Icaza <[email protected]>
* Eliminate warnings in a bunch of places.

svn path=/trunk/mcs/; revision=153952
2010-03-20 23:09:06 +00:00
Miguel de Icaza 9f53a9fd85 2009-05-16 Miguel de Icaza <[email protected]>
* Apply patch from Alex Shulgin
	<[email protected]> to support OSX in
	NetworkInformation classes.

svn path=/trunk/mcs/; revision=134277
2009-05-16 18:03:09 +00:00
Miguel de Icaza 54616d8862 2008-11-25 Atsushi Enomoto <[email protected]>
* Makefile : update old nunit options that break upgrade to 2.4.

2008-11-03 Gonzalo Paniagua Javier <[email protected]>

svn path=/trunk/mcs/; revision=120282
2008-11-29 20:25:30 +00:00
Gonzalo Paniagua Javier ec5069a12d 2008-11-29 Gonzalo Paniagua Javier <[email protected]>
* IPAddressCollection.cs: added an internal method to make the
	collection read-only.
	* IPInterfaceProperties.cs: read DNS client configuration from
	/etc/resolv.conf.
	* NetworkInterface.cs: dummy Speed property for linux.

	Bug #450211 fixed.


svn path=/trunk/mcs/; revision=120281
2008-11-29 19:09:46 +00:00
Gonzalo Paniagua Javier 0ab75f9991 2008-10-04 Gonzalo Paniagua Javier <[email protected]>
* NetworkInterface.cs: detect wireless 802.11 on linux.


svn path=/trunk/mcs/; revision=114857
2008-10-05 02:01:08 +00:00
Gonzalo Paniagua Javier 7de20eb8b6 2008-09-28 Gonzalo Paniagua Javier <[email protected]>
* NetworkInterface.cs: special case for loopback interfaces so that
	their a physical interface address is PhysicalInterfaceAddress.None.
	Fixes bug #422118.


svn path=/trunk/mcs/; revision=114343
2008-09-28 23:20:11 +00:00
Marek Habersack 8d78815a10 2008-07-14 Marek Habersack <[email protected]>
* NetworkInterface.cs: implemented support for Linux. Parts
	contributed by Eric Butler ([email protected]), thanks!

	* GatewayIPAddressInformationCollection.cs,
	IPInterfaceProperties.cs, IPAddressInformationCollection.cs: added
	support for Linux. Patch contributed by Eric Butler
	([email protected]), thanks!

	* IPv4InterfaceProperties.cs: implemented support for Linux.

	* LinuxNetworkInterfaceMarshal.cs: added. Contains a set of
	Linux-specific structures required for accessing the network
	information. Patch contributed by Eric Butler
	([email protected]), thanks!

	* MulticastIPAddressInformation.cs: added support for Linux
	multicast information. Patch contributed by Eric Butler
	([email protected]), thanks!

	* IPv4InterfaceStatistics.cs: use the parent IfacePath to get the
	path to the interface description file.

	* UnicastIPAddressInformation.cs: added stubs for
	LinuxUnicastIPAddressInformation. Patch contributed by Eric Butler
	([email protected]), thanks!

	* Ping.cs: Use /bin/ping when running as non-root user
	(implementation by Jackson Harper <[email protected]>) or use
	raw sockets if running as root or if the current process has the
	CAP_NET_RAW Linux capability set while running as an unprivileged
	user.


svn path=/trunk/mcs/; revision=107890
2008-07-14 15:37:21 +00:00
Marek Safar bdd9de656e Fixed few warnings
svn path=/trunk/mcs/; revision=107455
2008-07-08 10:34:18 +00:00
Miguel de Icaza bd9e32f5d7 Commit
svn path=/trunk/mcs/; revision=97901
2008-03-10 20:11:46 +00:00
Miguel de Icaza a365c3318d 2008-02-18 Miguel de Icaza <[email protected]>
* IPv4InterfaceStatistics.cs: Implemented Linux support.

	* NetworkInterface.cs: Implemented Linux support.

	TODO: still missing GetIPProperties.

svn path=/trunk/mcs/; revision=96155
2008-02-19 15:24:19 +00:00
Marek Safar e61dde083e Warnings cleanup
svn path=/trunk/mcs/; revision=89678
2007-11-15 14:14:49 +00:00
Miguel de Icaza c54dd89a05 2007-09-29 Miguel de Icaza <[email protected]>
* NetworkInterface.cs (GetAllNetworkInterfaces): return an empty
	array instead of throwing an exception on operating systems where

svn path=/trunk/mcs/; revision=86646
2007-09-29 19:59:03 +00:00
Atsushi Eno 69fc63dda1 2007-09-03 Atsushi Enomoto <[email protected]>
* IPGlobalStatistics.cs : Mib-* class is nonpublic.
	* Win32NetworkInterfaceMarshal.cs IPv4InterfaceProperties.cs
	  IPGlobalProperties.cs IPInterfaceProperties.cs
	  NetworkInterface.cs : move Win32NetworkInterfaceMarshal.FixedInfo to
	  Win32_FIXED_INFO.Instance and share it with Win32IPGlobalProperties.
	  Fixed GetUdp[6]Table() / GetTcp[6]Table() marshalling issue.


svn path=/trunk/mcs/; revision=85207
2007-09-03 08:29:38 +00:00
Atsushi Eno 7fb299fbbe 2007-08-29 Atsushi Enomoto <[email protected]>
* System.dll.sources : added Win32NetworkInterfaceMarshal.cs.

	* NetworkInterface.cs,
	  IPv4InterfaceStatistics.cs
	  IPInterfaceProperties.cs
	  IPv4InterfaceProperties.cs
	  IPv6InterfaceProperties.cs
	  IPAddressCollection.cs
	  GatewayIPAddressInformation.cs
	  GatewayIPAddressInformationCollection.cs
	  IPAddressInformation.cs
	  IPAddressInformationCollection.cs
	  MulticastIPAddressInformation.cs
	  MulticastIPAddressInformationCollection.cs
	  UnicastIPAddressInformation.cs
	  UnicastIPAddressInformationCollection.cs
	  Win32NetworkInterfaceMarshal.cs (new) :
	  NetworkInterface implementation using Win32 API.

	  Not sure how MIB-based implementation (for Linux) is possible but
	  it will follow.


svn path=/trunk/mcs/; revision=85018
2007-08-29 18:05:59 +00:00
Gonzalo Paniagua Javier 601398134b 2006-02-24 Gonzalo Paniagua Javier <[email protected]>
* UnicastIPAddressInformation.cs:
	* PingException.cs:
	* TcpConnectionInformation.cs:
	* IPv4InterfaceStatistics.cs:
	* NetworkInformationException.cs:
	* IPAddressInformation.cs:
	* MulticastIPAddressInformationCollection.cs:
	* TcpStatistics.cs:
	* IPGlobalStatistics.cs:
	* NetworkInformationPermission.cs:
	* MulticastIPAddressInformation.cs:
	* IcmpV4Statistics.cs:
	* IcmpV6Statistics.cs:
	* IPv4InterfaceProperties.cs:
	* PhysicalAddress.cs:
	* IPv6InterfaceProperties.cs:
	* GatewayIPAddressInformationCollection.cs:
	* ChangeLog: Modified file.
	* UnicastIPAddressInformationCollection.cs:
	* IPAddressCollection.cs:
	* NetworkInformationPermissionAttribute.cs:
	* Ping.cs:
	* NetworkChange.cs:
	* IPAddressInformationCollection.cs:
	* UdpStatistics.cs:
	* GatewayIPAddressInformation.cs:
	* IPGlobalProperties.cs:
	* IPInterfaceProperties.cs:
	* NetworkInterface.cs: implemented or stubbed out.


svn path=/trunk/mcs/; revision=57264
2006-02-24 22:47:15 +00:00