My system has 3 active network interfaces:
- 192.168.1.7 (Wireless adapter)
- 192.168.247.1 (virtual VMWare Ethernet adapter)
- 169.254.54.231 (another VMWare Ethernet adapter)
I'm trying to set up an UDP socket listening for SSDP broadcasts on port 1900 on all interfaces, however I don't seem to receive all broadcast datagrams but only some.
This is my code:
static void Main(string[] args) {
IPEndPoint broadcastEP =
new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900);
using (var udp = new UdpClient(broadcastEP.Port)) {
udp.JoinMulticastGroup(broadcastEP.Address);
while (true) {
IPEndPoint remoteEP = null;
Console.WriteLine("Listening for data on port " + broadcastEP.Port);
byte[] buffer = udp.Receive(ref remoteEP);
Console.WriteLine("Received " + buffer.Length + " data bytes from " + remoteEP);
}
}
}
If I now sent a broadcast datagram from another process, the above code should pick it up, right?
However when I execute this code in another process, the first process will only pick up the broadcast, if it's been sent from the 192.168.1.7 interface. If I send a broadcast from one of the other interfaces, the first process simply won't receive it. I can see that the broadcast is actually being sent in Wireshark...am I missing something?
static void Main(string[] args) {
var ifs = new IPAddress[] {
IPAddress.Parse("192.168.1.7"),
IPAddress.Parse("192.168.247.1"),
IPAddress.Parse("169.254.54.231")
};
IPEndPoint broadcastEP =
new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900);
using (UdpClient cli = new UdpClient(new IPEndPoint(ifs[0], 0))) {
IPEndPoint ep = new IPEndPoint(broadcastEP.Address, broadcastEP.Port);
int n = cli.Send(new byte[] { 1, 2, 3, 4 }, 4, ep);
Console.WriteLine("Sent " + n + " bytes to " + ep);
}
}
I know Windows runs a service (called SSDPSRV) listening for SSDP broadcasts on port 1900. Could that possibly "swallow" datagrams, so that they won't be delivered to my process? If so, is there anything I can do about this?
Thanks