Commit c5eb3259 authored by 李卓浩's avatar 李卓浩 Committed by Jason Song

优化网卡地址优先级 (#1986)

优化网卡地址优先级,index低的网卡地址优先级高
parent f7ed4f74
...@@ -7,6 +7,7 @@ import java.net.SocketException; ...@@ -7,6 +7,7 @@ import java.net.SocketException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
...@@ -98,7 +99,15 @@ public enum NetworkInterfaceManager { ...@@ -98,7 +99,15 @@ public enum NetworkInterfaceManager {
try { try {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
List<NetworkInterface> nis = interfaces == null ? Collections.<NetworkInterface>emptyList() : Collections.list(interfaces); List<NetworkInterface> nis = interfaces == null ? Collections.<NetworkInterface>emptyList()
: Collections.list(interfaces);
//sort the network interfaces according to the index asc
Collections.sort(nis, new Comparator<NetworkInterface>() {
@Override
public int compare(NetworkInterface nis1, NetworkInterface nis2) {
return Integer.compare(nis1.getIndex(), nis2.getIndex());
}
});
List<InetAddress> addresses = new ArrayList<>(); List<InetAddress> addresses = new ArrayList<>();
InetAddress local = null; InetAddress local = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment