Today I was working on a service discovery algoritm using C# sockets sending and receiving broadcast packets. It worked fine when the computer in use is having just one network interface, but testing on a different machine, I found out that even while binding the socket to IPAddress.Any, it still picks just one of the interfaces to send out the packet.

The solution is to use the ‘do not route’ option on the socket. The code becomes: