title: UDP broadcast on machine with multiple network adapters on Windows with native C++
body: <p>I need to do UDP broadcast (I recognize this should ideally be multicast instead) on a Windows machine with multiple network adapters using native C++ code.</p>
  
  <p>Currently, I'm setting the SO_BROADCAST socket option on the socket to allow broadcast and am then sending to the INADDR_BROADCAST address (255.255.255.255).  This doesn't reliably work on a machine with multiple network adapters.</p>
  
  <p>I've been searching around and found tons of questions about this on Stack Overflow.  From what I can tell, the best approach seems to be to figure out the broadcast IP for each  network adapter and then loop over those sending to each one.</p>
  
  <p>So, for example, if my machine has a network adapter with a 10.0.0.x IP address and another one with a 192.168.1.x, then I need to send the message to 10.0.0.255 and 192.168.1.255.</p>
  
  <p>Despite all the questions/answers I've looked through, I haven't been able to connect the dots to get the above list of addresses.</p>
  
  <p>Can anyone point me in the right direction?  For example, I found some sample code for using GetAdaptersAddresses to enumerate the IP addresses, but I don't see where you can get the subnet mask for each address.  Without the subnet mask I can't determine the broadcast address.  I need the list of IP addresses, and the subnet mask for each one so I can form the list of broadcast addresses to send to.</p>