1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-06 02:11:06 +09:00

GetNetworkInterface() now verified there's ipv4 addresses available

This commit is contained in:
lidgren
2013-04-08 07:40:26 +00:00
parent 900e280481
commit 772dceefcb

View File

@@ -223,10 +223,17 @@ namespace Lidgren.Network
if (adapter.OperationalStatus != OperationalStatus.Up) if (adapter.OperationalStatus != OperationalStatus.Up)
continue; continue;
// A computer could have several adapters (more than one network card) // make sure this adapter has any ipv4 addresses
// here but just return the first one for now... IPInterfaceProperties properties = adapter.GetIPProperties();
foreach (UnicastIPAddressInformation unicastAddress in properties.UnicastAddresses)
{
if (unicastAddress != null && unicastAddress.Address != null && unicastAddress.Address.AddressFamily == AddressFamily.InterNetwork)
{
// Yes it does, return this network interface.
return adapter; return adapter;
} }
}
}
return best; return best;
} }