Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6558853
Votes 0
Synopsis getHostAddress() on connections using IPv6 link-local addrs should have zone id
Category java:classes_net
Reported Against
Release Fixed 7(b27)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs
Submit Date 17-MAY-2007
Description
FULL PRODUCT VERSION :
java version "1.6.0_01"
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)

The bug also occurs in:

java version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Linux xxxxxx.xxxxx.xxxxx.com 2.6.20-1.2944.fc6 #1 SMP Tue Apr 10 18:46:45 EDT 2007 i686 i686 i386 GNU/Linux

EXTRA RELEVANT SYSTEM CONFIGURATION :
My system is IPv6 capable.

A DESCRIPTION OF THE PROBLEM :
If my Java program on Linux (Fedora Core 6) uses an IPv6 link-local address to establish an outgoing TCP connection, or accepts an incoming TCP connection from an IPv6 peer using a link-local address, then Socket.getInetAddress().getHostAddress() returns a string that should contain the zone identifier (e.g., %2 or %eth0), but doesn't.

For example, if my code does:

      Socket socket = new Socket("fe80::201:6cff:fe82:7394%eth0", 12345);

then once the connection is established, I use the expression socket.getInetAddress().getHostAddress(), I expect the resulting string to be "fe80::201:6cff:fe82:7394%eth0" or (in my case) "fe80::201:6cff:fe82:7394%2", but instead I get "fe80::201:6cff:fe82:7394", which by itself is not a usable address.

The same is true if the socket is created by:

      ServerSocket serverSocket = new ServerSocket(12345);
      Socket socket = serverSocket.accept();

This case is actually the more important one since my code doesn't have any other way to know who the peer is, or what local interface should be used to reach the peer.

I believe the bug is in j2se/src/share/native/java/net/net_util.c, in the NET_SockaddrToInetAddress() function.  The function correctly fills in the Inet6Address.scope_id field, but never sets the scope_id_set flag to true.  Without scope_id_set being true, Inet6Address.getHostAddress() won't append the scope id to the string it creates.  Presumably you would want to set the flag to true only if the address is a link-local address, because strangely, Inet6Address.getHostAddress() appends it whenever it's available, even if the address being formatted is not a link-local address.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use the Socket class to establish an outgoing TCP connection to an IPv6 link-local address that contains a zone id, or accept an incoming TCP connection from a peer that connected to a link-local address.  Then call Socket.getInetAddress().getHostAddress().

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The expected result is to see a zone identifier as part of the string produced by getHostAddress().
ACTUAL -
The actual result is that no zone identifier appears on the address.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Socket socket = new Socket("fe80::201:6cff:fe82:7394%eth0", 12345);
System.out.println(socket.getInetAddress().getHostAddress());

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

CUSTOMER SUBMITTED WORKAROUND :
I suppose one could call isLinkLocalAddress().  If that is true and the InetAddress is an instance of Inet6Address and if the result of ((Inet6Address) addr).getScopeId() is non-zero, one could append the correct zone identifier information via code.
Posted Date : 2007-05-17 16:50:43.0
Work Around
N/A
Evaluation
The issue seems indeed to come from the native code as mentioned in the description.
scope_id_set should be set as well.
Will fix as soon as possible.
Posted Date : 2008-02-28 15:10:03.0
Comments
  
  Include a link with my name & email   

Submitted On 22-APR-2008
I have recently submitted a new bug (Review ID: 1224956), but  it is a dupe of this one. Sorry.



PLEASE NOTE: JDK6 is formerly known as Project Mustang