Using C++Builder2006
I'm modifying an old, small program which do these things:
- send a UDP broadcast message (using the 255.255.255.255 address)
- get the answer from all the connected devices (hardware stuffs equipped with a RabbitCore RCM3200)
- Optionally broadcast another UDP message containing the MAC address of one of them and the correct network configuration that that device must set for itself.
(This 'cause the device can have a wrong IP/Netmask when installed and there's a need for a method IP-independent to set it. This is a well established method from the device producer, so it cannot be changed, i'm just describing what i'm doing).
The problem i'm facing is well described here: in short, Win7 does'nt send the UDP message through all the interfaces, but only through the "preferred" one. Since the program was built using an Indy UDPClient socket (TIdUDPClient) i'd like to keep it as it is.
Questions:
- There's a way to "force" the UDP socket to send thru a specific Network interface? This way i could "manually" loop and send the broadcast to all the (relevant) networks
- If not.... what should i do to obtain the same result?
TIdUDPClient
has aBoundIP
property for that exact purpose. You will have to callTIdUDPClient.Binding.CloseSocket()
each time you want to change theBoundIP
, unless you bind a differentTIdUDPClient
object for each adapter.Depending on the version of Indy you are using, you can use the
TIdStack.LocalAddresses
property, or theTIdStack.AddLocalAddressesToList()
orTIdStack.GetLocalAddressList()
method, to get a list of available local IP addresses that you can then loop through.