TTL ignored when sending Multicast UDP Datagram to IPv4 address via IPv6 socket

Alan Bateman Alan.Bateman at Sun.COM
Fri Jun 1 00:20:31 PDT 2007


Don Coleman wrote:
> I'm have a problem setting TTL when sending Multicast packets to an
> IPv4 address over an IPv6 socket.
>
> Setting the TTL in Java has no effect when sending to an IPv4 address.
> It is always 1.
>
> This is only a problem on Linux, it works fine on OS X, Solaris and 
> Windows.
>
> This problem exists with JDK5, but it looks like it's also in the JDK7 
> code.
>
> https://openjdk.dev.java.net/source/browse/openjdk/jdk/trunk/j2se/src/solaris/native/java/net/PlainDatagramSocketImpl.c?annotate=237 
>
>
> on line 1873 IPV6_MULTICAST_HOPS is set
> for Linux I think we need also need to set IP_MULTICAST_TTL
>
> I've attached sample Java and C code that demonstrates the problem
> here https://bugs.launchpad.net/ubuntu/+bug/112257
>
> Any thoughts if this is a Java problem or a Linux kernel bug?
The bug tracking this one is:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6250763

At least in older kernels, it wasn't possible to set IPv4 multicast 
options on IPv6 sockets (the setsockopt would fail). Edward Wang has 
been testing with recent kernels and has results that suggest that 
setting the IPv4 options work now. I believe he has a fix/patch in the 
works to address this (Edward - can you comment?).

If you need a workaround then run with -Djava.net.preferIPv4Stack=true 
so that all sockets are IPv4 (even if the machine has IPv6 enabled).

-Alan.













More information about the net-dev mailing list