JDK-7163874 : InetAddress.isReachable should support pinging 0.0.0.0
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2012-04-24
  • Updated: 2013-06-26
  • Resolved: 2012-05-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u40Fixed 8 b40Fixed
Description
FULL PRODUCT VERSION :
openjdk version "1.8.0-internal-fastdebug"
OpenJDK Runtime Environment (build 1.8.0-internal-fastdebug-deven_2012_04_23_17_22-b00)
OpenJDK Server VM (build 24.0-b07-fastdebug, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux deven 3.0.0-17-generic #30-Ubuntu SMP Thu Mar 8 17:34:21 UTC 2012 i686 i686 i386 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
There is a test case Javanet.java can reproduce this problem. Please use root privilege to run this test case(create raw socket need root privilege).

The root cause is that ping4 method in Inet4AddressImpl.c does a check of sending and receiving address.
(him->sin_addr.s_addr == sa_recv.sin_addr.s_addr)

This is not true for InetAddress 0.0.0.0. We can using ping command on Linux to confirm it:

ping 0.0.0.0
ING 0.0.0.0 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_req=1 ttl=64 time=0.024 ms
64 bytes from 127.0.0.1: icmp_req=2 ttl=64 time=0.025 ms

REGRESSION.  Last worked in version 7

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run Javanet.java with root previlege.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The target ip is 0.0.0.0
the target is reachable: true
Test passed
ACTUAL -
The target ip is 0.0.0.0
the target is reachable: false
Test failed
Exception in thread "main" java.lang.Exception: address 0.0.0.0 can not be reachable!
    at Javanet.main(Javanet.java:40)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Javanet {
    public static void main(String args[]) throws Exception {
        InetAddress inetAddress = InetAddress.getByName("0.0.0.0");
        System.out.println("The target ip is " + inetAddress.getHostAddress());
        boolean b = inetAddress.isReachable(3000);
        System.out.println("the target is reachable: " + b);
        if (b == true) {
            System.out.println("Test passed ");
        } else {
            System.out.println("Test failed ");
            throw new Exception("address " + inetAddress.getHostAddress()
                            + " can not be reachable!");
        }
    }
 }
---------- END SOURCE ----------

Comments
changeset id: http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/c5a07e3dca63
03-05-2013

EVALUATION This isn't really a bug and highly platform specific if the native ping command can ping this address.
24-04-2012