My machine has 3 network adapters. it is connected to other machines via all those three adapters. Each connection is a different subnet. So in total I have my machine connected to three subnets. Now I want to broadcast a UDP packet to other machines. When I do so, the broadcast packet goes only from one network interface instead of all the three. I know I can bind the specific network adapter address to a socket but I want only one socket to control the communication. How can I broadcast UDp packets through all the three interfaces using only one socket bound to a port say 5000?
Please help me!
what do you mean by "broadcast packet"? Do you use a broadcast address or do you just want to send the packet out on all interfaces of your machine? Depending on the underlying OS and configuration I suspect your problem isn't even a problem in the application. Usually the OS decides based on routing table entries to which interfaces a network packet should be sent. This way the interfaces bound to other address ranges/subnets don't even see packets when the OS "knows" (from the routing table) that the receiver is only reachable via another interface. But it's hard to give good advices without knowing more details. Maybe it would be a good idea to tell us what problem you are trying to solve this way ;-)
Joined: Feb 26, 2012
Actually I am developing a java program that should send a broadcast packet out of all its interfaces to the other machines attached to it by using the subnet broadcst address for each interface. When those remote machines receive the packet, they return their IP address and some information related to them.
UPDATE: I have one more problem, when I try to get the broadcast address using interfaceAddress.getBroadcast(), it gives me 255.255.255.255. This should return the subnet broadcast address like 10.0.0.3 (subnet mask /30, network id 10.0.0.0, hosts are connected as 10.0.0.1, 10.0.0.2)