United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7163874 InetAddress.isReachable should support pinging 0.0.0.0
JDK-7163874 : InetAddress.isReachable should support pinging 0.0.0.0

Details
Type:
Enhancement
Submit Date:
2012-04-24
Status:
Closed
Updated Date:
2013-05-06
Project Name:
JDK
Resolved Date:
2012-05-23
Component:
core-libs
OS:
linux
Sub-Component:
java.net
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:

Sub Tasks

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
EVALUATION

This isn't really a bug and highly platform specific if the native ping command can ping this address.
                                     
2012-04-24
changeset id:
  http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/c5a07e3dca63
                                     
2013-05-03



Hardware and Software, Engineered to Work Together