Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6210227

REGRESSION: Socket.getLocalAddress() returns address of 0.0.0.0 on outbound TCP

    XMLWordPrintable

Details

    • b05
    • x86
    • solaris_9, windows_2000, windows_xp

    Backports

      Description

        FULL PRODUCT VERSION :
        java version "1.5.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
        Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Linux unununium 2.4.21-20.EL #1 Wed Aug 18 20:58:25 EDT 2004 i686 i686 i386 GNU/Linux


        A DESCRIPTION OF THE PROBLEM :
        Calling Socket.getLocalAddress() used to return the IP address of the interface over which the connection to the remote was was being made. Now it alway returns 0.0.0.0. We have written a sample program which demonstrates the bug. The program works with jre 1.4.2, but not with 5.0. This problem seems to be a linux only problem. It works fine on Windows. We did try it on both red hat linux 7.3 and Red Hat Enterprise Linux 3.0, and it failed on both of those.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the test program provided:

        usage: java Interfaceid <hostname> where <hostname> is a website such as google.com

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        $ java Interfaceid google.com
        get ip and hostname of our interface to google.com
        local ip is 192.168.100.53
        local hostname is curium.avamar.com

        ACTUAL -
        $ java Interfaceid google.com
        get ip and hostname of our interface to google.com
        local ip is 0.0.0.0
        local hostname is 0.0.0.0


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.util.*;
        import java.net.*;

        public class Interfaceid {
         
        public static void main(String[] args) {
                    if( null == args[0] ) {
                                System.out.println("usage: java Interfaceid <hostname> where <hostname> is a website such as google.com");
                    } else {
                                String sHostname = args[0];
                    System.out.println("get ip and hostname of our interface to "+sHostname);
                    try {
                                InetAddress ina = InetAddress.getByName( sHostname );
                                InetSocketAddress isa = new InetSocketAddress( ina, 80 );
                        Socket s = new Socket();
                        s.connect( isa, 1000 );
                        InetAddress iaLocal = s.getLocalAddress(); // if this comes back as 0.0.0.0 this would demonstrate issue
                        String sLocalHostname = iaLocal.getHostName();
                        System.out.println("local ip is "+iaLocal.getHostAddress() );
                        System.out.println("local hostname is "+sLocalHostname );
                    } catch(Exception e) {
                                System.out.println("Exception happened");
                    }
                }
        }
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        We have not been able to find any workaround that will give us the IP address of the NIC being used for the connection on a dual NIC machine. We also tried using Socket.getLocalSocketAddress() , and this failed in the same way. We presume that the same underlying code is used to get the IP address.

        Release Regression From : 1.4.2
        The above release value was the last known release where this
        bug was known to work. Since then there has been a regression.
        ###@###.### 2004-12-17 21:52:13 GMT

        Attachments

          Issue Links

            Activity

              People

                yuwangsunw Yujiang Wang (Inactive)
                gmanwanisunw Girish Manwani (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: