4

Creating a Mono console application in MonoDevelop targeted at Mono/.NET 4.0 on OS X, to function as a TCP socket server.

The following line of code fails (that you would normally use on the Windows side of things):

var interfaces = NetworkInterface.GetAllNetworkInterfaces();

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

Best I can tell this is only supported on Windows and Linux. However it seems there is another method designed for Mac:

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

While that appears to be recognized by MonoDevelop, it fails to compile with a The type or namespace 'MacOsNetworkInterface' does not exist in the namespace 'System.Net.NetworkInformation'. error. Already have references to System and System.Net.

What am I missing?

Edit: Discovered that NetworkInterface.GetAllNetworkInterfaces() does work when I create a new C# console app in MonoDevelop, but doesn't work within an existing project (NetworkComms.net) - they are both targeted the same, Mono, .NET 4.0 with same references to System and System.Net v4.0.0.0, what's the difference?

user7116
  • 63,008
  • 17
  • 141
  • 172
Brandon
  • 13,956
  • 16
  • 72
  • 114

1 Answers1

1

If you need to call into low-level OS X APIs/Frameworks, MonoMac is your best candidate. However, not all OS X Frameworks are bound in MonoMac, yet. From the Apple Developer documentation, I take that you would need the functions from the SystemConfiguration API which isn't bound by MonoMac currently.

But you can always create a binding for the missing functions yourself using DllImport. I've recently done it with the DiskArbitration Framework (which isn't bound either) and you could use that as a reference: http://git.gnome.org/browse/banshee/tree/src/Backends/Banshee.Osx/Banshee.Hardware.Osx/LowLevel?id=136fcbcc2e0421aba6be79306dc111fdabb3c749

Dynalon
  • 6,577
  • 10
  • 54
  • 84