title: C++ WinSock choose local interface for connection
body: <p>I have a system with multiple NIC and so multiple ip addresses and I've to use an SDK whose initialization  that needs my local address and the remote address.</p>
  
  <p>I want to autoselect the local endpoint. At the moment I'm enumerating all local addresses (via <code>GetAdaptersAddresses</code>) checking for the best match ( to be correct I should use the subnet mask).</p>
  
  <p>But given that this  job is done by the routing table is there any Windows API that given a remote address gives me back the right local endpoint ?</p>