I've run into a known bug with Java 6 on Windows. My understanding is that the normal way to get the netmask is to look up the network prefix length and do some bit shifts. The problem is that on Windows the prefix length is often returned incorrectly, so we get a 128 when we should get a 24 or 20.
In this solution, it is suggested to put -Djava.net.preferIPv4Stack=true
on the Java command line. Unfortunately, on Windows 7, adding that as either a VM parameter or on the Java command line seems to have no effect.
(a) Does anyone know any OTHER work-arounds for this problem that might still work on Windows 7?
(b) Alternatively, is there an entirely different way to get the netmask that is reliable?
Thanks!
-Djava.net.preferIPv4Stack=true
VM option does work in my case under Windows 7 for JRE 1.6. I put this in my Java code asSystem.setProperty("java.net.preferIPv4Stack","true")
. Unless, something (library or whatever) is resetting it. Can you show your IP netmask codes? – Ernaernald