OPERATING SYSTEM(S): Any Unix-like - e.g. Linux, Solaris FULL JDK VERSION(S): Any Java 5 or Java 6 DESCRIPTION: InetAddress.isReachable() will not work for super users with "large" process ids. This is because the process id is passed as an unsigned 16-bit value in the ICMP echo request, and the echoed result compared with the original 32-bit process id. My fix was to change the data type into which we get the process id. The original (Mike Muuss) "ping" code simply masks the process id with 0xFFFF. Either solution will work fine. TESTCASE: Use this class as a superuser, running in a process with a process id > 0xFFFF. public class TestIsReachable { public static void main(String []args) { try { java.net.InetAddress addr = java.net.InetAddress.getByName(args[0]); if(addr.isReachable(1000) == true) { System.out.println(args[0] + " is Reachable!\n"); } else { System.out.println(args[0] + " is NOT Reachable!\n"); } } catch (java.lang.Exception e) { System.out.println(e); } } }
|