Broadcast UDP paket with wrong source ip address

M

Mali Findik

Hi @ll,

i've got problems with sending an UDP broadcast datagramm over two
network interfaces.

The code is like this:
<Code>
UdpClient client = new UdpClient();
IPEndPoint remoteEndPoint =
new IPEndPoint(IPAddress.Parse("255.255.255.255"), 1234);
byte [] data = {(byte)42};
client.Send(data, data.Length, remoteEndPoint);
</Code>

I've got two network interfaces, let us say for example:
interface_1 with ip 192.168.0.1
interface_2 with ip 10.1.0.1

Now, if I sniff on the interface_1 I got the correct source ip
192.168.0.1, but I sniff on the second interface, i got 192.168.0.1 as
source ip, anyway :(

Does somebody know, how to fix that problem?

Best regards,

Mali
 
P

Peter Duniho

[...]
I've got two network interfaces, let us say for example:
interface_1 with ip 192.168.0.1
interface_2 with ip 10.1.0.1

Now, if I sniff on the interface_1 I got the correct source ip
192.168.0.1, but I sniff on the second interface, i got 192.168.0.1 as
source ip, anyway :(

Does somebody know, how to fix that problem?

Not really. You don't have control over how data is sent from your
application; only in how it's received. You can bind to a specific IP
address to make the socket only receive on that address, but when
sending the network driver will determine what it thinks is the best
route for the data, and that's how the data will be sent.

There are ways to manipulate the routing, but IMHO it's not a good idea
to do so and I'm not aware of anything in .NET that allows that
directly anyway.

One possible workaround would be to use multicast instead of broadcast.
If I recall correctly (and I might not), you can configure the
multicast group on a specific adapter to ensure the source IP address
is as you desire.

But if you really need broadcast datagrams, I don't think there's a
good way to change the behavior the way you want to.

Pete
 
M

Mali Findik

Peter said:
[...]
I've got two network interfaces, let us say for example:
interface_1 with ip 192.168.0.1
interface_2 with ip 10.1.0.1

Now, if I sniff on the interface_1 I got the correct source ip
192.168.0.1, but I sniff on the second interface, i got 192.168.0.1 as
source ip, anyway :(

Does somebody know, how to fix that problem?


Not really. You don't have control over how data is sent from your
application; only in how it's received. You can bind to a specific IP
address to make the socket only receive on that address, but when
sending the network driver will determine what it thinks is the best
route for the data, and that's how the data will be sent.

There are ways to manipulate the routing, but IMHO it's not a good idea
to do so and I'm not aware of anything in .NET that allows that directly
anyway.

One possible workaround would be to use multicast instead of broadcast.
If I recall correctly (and I might not), you can configure the multicast
group on a specific adapter to ensure the source IP address is as you
desire.

But if you really need broadcast datagrams, I don't think there's a good
way to change the behavior the way you want to.

Pete


Thank you for your reply, Pete.

But it is not applicable for me to use multicast instead of broadcast.
Cause the receivers of the broadcast may be not in the same subnet.
They will rearrange their ip address depending on the source ip address
of the broadcast paket. And this is exact my problem.

Maybe there are some win api calls to manipulatethe udp packet directly?

Mali
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top