I have the following issue:
I want to send multicastd data to f.i. 224.0.12.13, but as the user's machine maybe have a lot of devices, the data is sent (obviously) to the route with the smallest metric. For instance, "route print" in windows tells me:
===========================================================================
Schnittstellenliste
38...00 15 5d 25 b1 ec ......Hyper-V Virtual Ethernet Adapter
33...3e 37 86 8b cd 0d ......Microsoft Wi-Fi Direct Virtual Adapter #4
47...3c 37 86 8b cd 0d ......Microsoft Wi-Fi Direct Virtual Adapter #5
7...3c 37 86 8b cd 0d ......NETGEAR A6150 WiFi USB 2.0 Adapter
1...........................Software Loopback Interface 1
===========================================================================
IPv4-Routentabelle
===========================================================================
Aktive Routen:
Netzwerkziel Netzwerkmaske Gateway Schnittstelle Metrik
0.0.0.0 0.0.0.0 192.168.10.1 192.168.10.49 35
127.0.0.0 255.0.0.0 Auf Verbindung 127.0.0.1 331
127.0.0.1 255.255.255.255 Auf Verbindung 127.0.0.1 331
127.255.255.255 255.255.255.255 Auf Verbindung 127.0.0.1 331
172.18.64.0 255.255.240.0 Auf Verbindung 172.18.64.1 271
172.18.64.1 255.255.255.255 Auf Verbindung 172.18.64.1 271
172.18.79.255 255.255.255.255 Auf Verbindung 172.18.64.1 271
192.168.10.0 255.255.255.0 Auf Verbindung 192.168.10.49 291
192.168.10.49 255.255.255.255 Auf Verbindung 192.168.10.49 291
192.168.10.255 255.255.255.255 Auf Verbindung 192.168.10.49 291
224.0.0.0 240.0.0.0 Auf Verbindung 127.0.0.1 331
224.0.0.0 240.0.0.0 Auf Verbindung 192.168.10.49 291
224.0.0.0 240.0.0.0 Auf Verbindung 172.18.64.1 271
255.255.255.255 255.255.255.255 Auf Verbindung 127.0.0.1 331
255.255.255.255 255.255.255.255 Auf Verbindung 192.168.10.49 291
255.255.255.255 255.255.255.255 Auf Verbindung 172.18.64.1 271
===========================================================================
As you can see, there are three 224.0.0.0 routes. Java typically picks the one in the 172.16.64.1 net/device and not the desired 192.168.10.49
In my code I know the device's name and IP that should be used to send multicast data.
But how can I overcome the operating system to pick the one with the smallest metric?
Changing the metric is not an option. It must be possible to tell java which interface to use when sending multicast data and not choose with help of routing table.
Can anyone help?
My code snippet to test sending and watching which interface is taken with help of wireshark:
int port = 5000;
String group = "224.0.23.13";
final MulticastSocket s = new MulticastSocket();
byte[] buf = new byte[10];
for (int i = 0; i < buf.length; i++) {
buf[i] = (byte) i;
}
final DatagramPacket pack = new DatagramPacket(buf, buf.length, InetAddress.getByName(group), port);
s.send(pack);