G
Guest
I'm getting some weirdness when sending out broadcasts on a system with two
adapters. The adapters are configured with IP addresses on seperate subnets.
Packets get sent out on each interface, but the source addresses (as seen
from a packet sniffer) on both packets is the IP address for adapter #1. This
creates a problem when clients on adapter #2's network try to respond because
they can't reach the source address on adapter #1's network.
Here's some code that illustrates the problem:
public static void Main(string[] args)
{
byte[] bytes = Encoding.UTF8.GetBytes("Testing broadcast...");
IPEndPoint endpoint = new IPEndPoint(IPAddress.Broadcast, 10485);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
socket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.Broadcast, 1);
socket.SendTo(bytes, endpoint);
}
My question is, am I doing something wrong? Or is this expected (or even
desired) behavior? If so, any ideas how I could make it work correctly?
adapters. The adapters are configured with IP addresses on seperate subnets.
Packets get sent out on each interface, but the source addresses (as seen
from a packet sniffer) on both packets is the IP address for adapter #1. This
creates a problem when clients on adapter #2's network try to respond because
they can't reach the source address on adapter #1's network.
Here's some code that illustrates the problem:
public static void Main(string[] args)
{
byte[] bytes = Encoding.UTF8.GetBytes("Testing broadcast...");
IPEndPoint endpoint = new IPEndPoint(IPAddress.Broadcast, 10485);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
socket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.Broadcast, 1);
socket.SendTo(bytes, endpoint);
}
My question is, am I doing something wrong? Or is this expected (or even
desired) behavior? If so, any ideas how I could make it work correctly?