Page 1 of 1
UDP Broadcast on a specific nic
Posted: Fri Feb 13, 2009 7:10 am
by idle
I was trying to find a solution to send a udp broadcast out a specific nic on a system with multiple devices.
The problem is simply that if you have more than one nic
eg:
192.168.0.3 and 10.1.1.3
The broadcast will report the first address regardless which may not be the default device.
I didn't find any socket option solution to the problem, though I have at least found a solution that may work, I just don't know if it would hold.
Is it safe to assume that the default gateway is the same range as the default device?
eg: if I enumerate the devices to get their IP's and gateway
I get a list like this
IP = 192.168.0.3
gateway =
IP = 10.1.1.3
gateway = 10.1.1.1
Posted: Tue Feb 17, 2009 11:30 am
by real
What is you intention? To send the message only to a limited network or to ALL networks?
Posted: Tue Feb 17, 2009 11:39 am
by idle
Just across the LAN.
Posted: Tue Feb 17, 2009 12:24 pm
by pdwyer
In command prompt "Route Print" will show you which traffic will go where, "Route Add" will add a temporary or persistant route (persistant stays after a reboot).
Route /? will give you the details of how to use them.
We use these things when we have a windows machine as a proxy between local network and a DMZ (with another firewall on the outside of that) and the server has a foot (nic) in each subnet.
One direction has to be default and hold the 0.0.0.0 then static routes of any size can have a next hop on an IP of a gateway in the subnet of one of the nics
It's a little confusing first time you use it but not too bad once you play with it a bit.
if you want some help with structuring the commands post (or PM) me the IPs, subnets, Gateways and the contents of "Route Print"
Posted: Tue Feb 17, 2009 10:27 pm
by real
I think a broadcast to 255.255.255.255 should reach all networks. Did you try it?
I wrote a lib to realize this and afaik it was able to broadcast via multiple nics. If you want to give it a try i would upload it to my website again...
Posted: Tue Feb 17, 2009 11:44 pm
by idle
Thanks, the solution I've got is working on my network but I just don't know if my logic is right or if it will hold for more complex networks.
When I send the broadcast it's sent out on all the interfaces but the problem is that it only reports the IP of the first interface and not the second.
So when a listening client gets the broadcast, the IP of the sender is still resolved as the first interface, which may not be the interface that the actual server application is listening on.
As long as the client and server are not separated by a router the Limited Broadcast will reach all the machines on the LAN.
As long as the default gateway is the same subnet that the Server application is listening on then, it's all good otherwise I need to find another solution.
Posted: Wed Feb 18, 2009 11:14 am
by Michael Vogel
I still have no idea what the target is
Standard broadcasts will be seen and read by all NICs and forwarded to the IP layer. Depending on what is inside the IP layer, the end device will answer or not.
That means, if a broadcast ping will be sent, the ICMP echo request won't be answered on certain OSs (or if a firewall does not allow this protocol etc.)
So if a client will uses a protocol (Purebasic program) which answers to your request, you will get not only one reply (if your sending device waits for multiple answers

)
Michael
Posted: Sat Feb 21, 2009 6:29 am
by idle
It's sorted now thanks.