UDP Broadcast on a specific nic

Just starting out? Need help? Post your questions and find answers here.
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

UDP Broadcast on a specific nic

Post 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
real
User
User
Posts: 49
Joined: Fri Oct 08, 2004 5:17 am

Post by real »

What is you intention? To send the message only to a limited network or to ALL networks?
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Post by idle »

Just across the LAN.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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"
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
real
User
User
Posts: 49
Joined: Fri Oct 08, 2004 5:17 am

Post 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...
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Post 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.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post 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 :wink: )

Michael
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Post by idle »

It's sorted now thanks.
Post Reply