By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,827 Members | 2,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,827 IT Pros & Developers. It's quick & easy.

Broadcast UDP paket with wrong source ip address

P: n/a
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
Nov 15 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 2007-11-15 05:31:51 -0800, Mali Findik <bl*****@gmx.netsaid:
[...]
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

Nov 15 '07 #2

P: n/a
Peter Duniho schrieb:
On 2007-11-15 05:31:51 -0800, Mali Findik <bl*****@gmx.netsaid:
>[...]
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
Nov 16 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.