private static int GetBestInterfaceForAddress(IPAddress addr)
{
int index;
Internals.SocketAddress address = new Internals.SocketAddress(addr);
int error = (int)Interop.IpHlpApi.GetBestInterfaceEx(address.Buffer, out index);
if (error != 0)
{
throw new NetworkInformationException(error);
}
return index;
}