In my application (admin web interface written in MVC3) running on open-embedded Linux I have to list all the TCP/IP settings. This includes IP-Adresse, Gateway and the subnet mask.
The following code runs well under MS .Net but Mono 2.10 throws a NotImplemntedException for the "IPv4Mask" property:
var ipProperties = networkIntf.GetIPProperties();
var unicastIpInfo = ipProperties.UnicastAddresses.FirstOrDefault();
var subnetMask = unicastAddress != null ? unicastAddress.IPv4Mask.ToString() : "";
Does anybody know how one can get the IPv4 subnet mask using Mono?
I found this question was asked already in 2009 but didn’t find any answer to it.
I took a look at some Mono sourcecode and extracted some code-snippets to build a helper that returns a the IPv4 subnet mask of the given network interface. The code is not an absolute beauty but it works.
Usage of the above helper is like this:
I didn’t yet manage to fix this in the Mono sourcecode as one needs to change quite some files in Mono to get the above information from the place where it is queried (LinuxNetworkInterface) to the place where it is used (LinuxUnicastIPAddressInfo). But I will post my code to the Mono bug-report so maybe one of the Mono developers can take a look.