获取主机网络连接信息时按索引从小到大排序,优先使用索引值小的网络接口。

This commit is contained in:
张家伟 2023-06-30 15:22:32 +08:00
parent 00228f3b3e
commit 1adc25308f

View File

@ -155,6 +155,9 @@ public class NetUtils {
log.warn("[Net] findNetworkInterface failed", e);
}
// sort by interface index, the smaller is preferred.
validNetworkInterfaces.sort(Comparator.comparingInt(NetworkInterface::getIndex));
// Try to find the preferred one
for (NetworkInterface networkInterface : validNetworkInterfaces) {
if (isPreferredNetworkInterface(networkInterface)) {