JDK-6572015 : Socket.getLocalAddress() returns 0.0.0.0 on outbound TCP for IPv6 sockets
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-06-20
  • Updated: 2024-05-21
  • Resolved: 2024-05-21
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
Tried all available 1.5 versions +
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
Have not tried 1.7.

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Dual IP stack (IPv4 and IPv6)

A DESCRIPTION OF THE PROBLEM :
This bug must be related to bug JDK-6210227, which has not been fixed despite the claimed "fixed" status.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Configure IPv6 an a Windows box.

2. The problem can be easily reproduced with the attached code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Originator's IP address of the outbound TCP connection.
ACTUAL -
0.0.0.0

ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error. The call just works incorrectly

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

import java.util.*;
import java.net.*;

public class Interfaceid {
 
/**
* In order to reproduce the bug the system that runs this class must support
* IPv6.
*/
public static void main(String[] args) {
            if( null == args[0] ) {
                        System.out.println("usage: java Interfaceid <IPv6address>");
            } 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 :
Unknown. Because of this problem it is impossible to implement RFC 2428 in Java.

Comments
Likely fixed with JDK-7009760. Windows XP is long gone, and sockets were reimplemented since this was reported.
21-05-2024

The original bug was against Windows XP which doesn't support dual-stack sockets. So I'll bet this issue is specific to the two-stack implementation.
05-12-2013

ran the sample above on three difference version of windows using version of 1.7 and there doesn't seem to be a problem. The correct local IP address is returned each time.
05-12-2013