[kaffe] ipv6 on freebsd problems & partial workaround

jrandom jrandom at i2p.net
Sun May 23 04:33:02 PDT 2004


g'morning y'all,

I just wanted to check in to see what the status of ipv6 socket support
was - from what I've seen on the list & in google, it should be working,
but I'm unfortunately running into failures opening up a socket to a peer
who has both an IPv6 and IPv4 address available (my machine only has an
IPv4 address).

% cat > testv6.java
import java.net.*;

public class testv6 {
 public static void main(String args[]) {
  try {
   Socket s = new Socket($somehost, 8887);
   System.out.println("Connected to " + s.getInetAddress());
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}
% javac testv6.java
% java -cp . testv6
java.io.IOException: Invalid argument
   at gnu.java.net.PlainSocketImpl.socketConnect (PlainSocketImpl.java)
   at gnu.java.net.PlainSocketImpl.connect (PlainSocketImpl.java:83)
   at java.net.Socket.connect (Socket.java:402)
   at java.net.Socket.connect (Socket.java:366)
   at java.net.Socket.<init> (Socket.java:292)
   at java.net.Socket.<init> (Socket.java:149)
   at testv6.main (testv6.java:6)
% telnet $somehost 8887
Trying $val:$val:$val::1...
Trying $someipv4...
Connected to $somehost.
Escape character is '^]'.
*a
Connection closed by foreign host.
% nslookup -type=any $somehost

Non-authoritative answer:
$somehost    internet address = $someipv4
$somehost    IPv6 address = $val:$val:$val::1

Machine is a freebsd 4.8-RELEASE box (smp VM on an i386 cluster) JVM is
kaffe from head on May 5th (with the URLConnection and html.java patches).
I'm rebuilding from CVS HEAD at the moment (but it usually takes a few
hours, and I didn't see any related changes in CVS since then).

Any suggestions on how I can help debug?  The furthest I got before
getting lost in C is trying to track down KCONNECT (but I didn't really
follow PlainSocketImpl.c too well - last time I hacked in C was before
IPv6).  On the other hand, my current workaround is quite ugly -

Index: InetAddress.java
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/net/InetAddress.java,v
retrieving revision 1.22
diff -u -r1.22 InetAddress.java
--- InetAddress.java    17 May 2004 22:25:05 -0000      1.22
+++ InetAddress.java    23 May 2004 09:19:13 -0000
@@ -649,6 +649,12 @@

     // Try to resolve the host by DNS
     InetAddress[] addresses = getAllByName(hostname);
+
+    // ugly hack to always prefer IPv4 addresses over IPv6
+    for (int i = 0; i < addresses.length; i++) {
+      if (addresses[i] instanceof Inet4Address)
+        return addresses[i];
+    }
     return addresses[0];
   }

This works and doesn't seem to violate any getByName contract, though it
obviously doesnt fix the IPv6 issue.  I tried it using that host's DNS
name, its IPv4 address, and its IPv6 address (the first two worked, the
IPv6 didnt).

To test this I had to revert to Release_1_1_5_Branch, apply the
freebsd2/md.h patch as well and tweak the above InetAddress.java patch to
work off that older code.  I would have preferred going against HEAD, but
even after reverting my copy of kjc.jar back a few days, I ran into
another kooky error:

 java/awt/peer/WindowPeer.java:41: error:Cannot find class "ContainerPeer" [JLS 8]

That didn't make any sense whatsoever, since ContainerPeer.java is in the
same dir, public, and I couldn't see anything wrong with it.

Is there anything I can do to help figure out whats up with the IPv6
support?

gracias,
=jr




More information about the kaffe mailing list