How do you get a list of network interfaces in Mono on Mac?

Create a Mono console application in MonoDevelop, designed for Mono / .NET 4.0 on OS X, to act as a TCP socket server.

The following line of code does not work (which you usually use on the Windows side):

var interfaces = NetworkInterface.GetAllNetworkInterfaces(); 

... with System.DllNotFoundException: iphlpapi.dll error System.DllNotFoundException: iphlpapi.dll

I can say that this is only supported on Windows and Linux. However, there seems to be another method developed for the Mac:

 System.Net.NetworkInformation.MacOsNetworkInterface.GetAllNetworkInterfaces(); 

Although this is apparently recognized by MonoDevelop, it cannot compile with the error The type or namespace 'MacOsNetworkInterface' does not exist in the namespace 'System.Net.NetworkInformation'. . There are already links to System and System.Net.

What am I missing?

Edit: It was discovered that NetworkInterface.GetAllNetworkInterfaces() works when I create a new C # console application in MonoDevelop, but it doesn’t work within an existing project ( NetworkComms.net ) - both of them are the same, Mono, .NET 4.0 with the same System references and System.Net v4.0.0.0, what's the difference?

+4
source share
1 answer

If you need to call the low-level OS X / Framework APIs , MonoMac is your best candidate. However, not all OS X Frameworks are connected in MonoMac. From the Apple Developer documentation, I suggest that you will need functions from the SystemConfiguration API , which is not currently associated with MonoMac.

But you can always create a binding for missing functions yourself using DllImport. I recently did this with the DiskArbitration Framework (which is not related either), and you can use this as a link: http://git.gnome.org/browse/banshee/tree/src/Backends/Banshee.Osx/Banshee.Hardware. Osx / LowLevel? Id = 136fcbcc2e0421aba6be79306dc111fdabb3c749

+1
source

All Articles