United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6587875 InetAddress.isReachable() will not work for super users with "large" process ids
JDK-6587875 : InetAddress.isReachable() will not work for super users with "large" process ids

Details
Type:
Bug
Submit Date:
2007-08-01
Status:
Closed
Updated Date:
2011-05-18
Project Name:
JDK
Resolved Date:
2011-05-18
Component:
core-libs
OS:
solaris_8
Sub-Component:
java.net
CPU:
sparc
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u2
Fixed Versions:

Related Reports
Backport:
Backport:

Sub Tasks

Description
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);
        }  
    }
}

                                    

Comments
WORK AROUND

Run as a normal user, not a superuser.
                                     
2007-08-01
EVALUATION

see description.
                                     
2007-08-03
SUGGESTED FIX

------- Inet4AddressImpl.c -------
342c342,343
<     jint pid, seq = 1;
---
>     jchar pid;
>     jint seq = 1;
347c348
<     pid = getpid();
---
>     pid = (jchar)getpid();


Similar change for Inet6AddressImpl also.
                                     
2007-08-03
EVALUATION

The unix version of Inet6AddressImpl does not have this problem, but the implementation was updated to reflect the changes in Inet4AddressImpl so that how we handle pids is consistent.
                                     
2007-08-08



Hardware and Software, Engineered to Work Together