I need to send multicast UDP packets to the loopback network device inside a Docker container (a requirement of the LCM Java library). I'm using (Ubuntu 22), installing net-tools
, and running the image with --priveleged
so that I can modify network settings. I'm following the LCM project instructions, as well as this SO answer, by running ifconfig lo multicast
followed by route add -net 224.0.0.0 netmask 240.0.0.0 dev lo
inside the container.
Running ip maddr show
shows me that the lo
device is indeed configured as multicast:
1: lo
inet 224.10.10.10
inet 224.0.0.1
inet6 ff02::1
inet6 ff01::1
I'm running the container on an OSX host. Despite all of the steps listed above, I still get errors about the multicast protocol being unavailable.
Minimal breaking example below. First do export JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"
(I believe LCM does this, and it eliminates further potential issues with IPv6 multicast not being supported), then run this in jshell
:
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
import java.net.SocketAddress;
var inetPort = 7667;
var sock = new MulticastSocket(inetPort);
var inetAddr = InetAddress.getByName("239.255.76.67");
SocketAddress socketAddr = new InetSocketAddress(inetAddr, inetPort);
sock.joinGroup(socketAddr, null);
The output is:
inetPort ==> 7667
sock ==> java.net.MulticastSocket@3eb07fd3
inetAddr ==> /239.255.76.67
socketAddr ==> /239.255.76.67:7667
| Exception java.net.SocketException: Protocol not available
| at Net.getInterface6 (Native Method)
| at DatagramChannelImpl.getOption (DatagramChannelImpl.java:427)
| at DatagramSocketAdaptor.getOption (DatagramSocketAdaptor.java:426)
| at DatagramSocketAdaptor.outgoingNetworkInterface (DatagramSocketAdaptor.java:657)
| at DatagramSocketAdaptor.defaultNetworkInterface (DatagramSocketAdaptor.java:672)
| at DatagramSocketAdaptor.joinGroup (DatagramSocketAdaptor.java:522)
| at DatagramSocket.joinGroup (DatagramSocket.java:1292)
| at MulticastSocket.joinGroup (MulticastSocket.java:371)
| at (#9:1)
What am I doing wrong here? How do I enable multicast networking with the loopback interface in a Docker container?