I am trying to send a multicast packet on a network interface with multiple host ip addresses(lets say ips A and B). How can I specify the source ip field of said multicast packet to the host ip that I prefer(A). Currently, multicast packets have their source ip as B. I would prefer to do it OS(Windows 10) level. How can I set this up correctly?
I am using java for the sender program and I found that for MulticastSocket objects setInterface(InetAddress inf) method can be used to (I assume) specify the chosen source ip address but DatagramChannel only allows setting network interface and I would much rather prefer to config this in OS level.
EDIT: forgot to add: route table's first row is Dest - (0.0.0.0) | Netmask - (0.0.0.0) | Gateway - Gateway IP | Interface - IP A with the lowest metric value of all the entries in the route table. Still multicast packets have ip B as their source
EDIT2: I tried the following Scenario 1:
- bind socket to wildcard address
- iterate over all valid interfaces
- set socket interface to each valid interface and send packets
- with this, I can send packets over multiple interfaces using single socket object
Scenario 2:
- bind socket to a specific local ip address (say IP1) on interface 1
- iterate over valid interfaces
- try to set socket interface to each interface and send packets
- in this one, interface setting doesnt do anything and all packets sent during iteration leave on the interface with IP1
Shortcoming of the first one is that while I can specify the network interface, I cannot specify the local ip if there are multiple local ip addresses on that interface, second one allows one to specify the local ip address but cannot iterate over all valid interfaces with only 1 socket. It seems I will need to create n sockets bound to n local ip addresses on n different interfaces to be able to send packets on n valid interfaces.