Skip to content

Commit

Permalink
优化网卡地址优先级 (apolloconfig#1986)
Browse files Browse the repository at this point in the history
优化网卡地址优先级,index低的网卡地址优先级高
Accelerator96 authored and sync_forks committed Jul 31, 2024
1 parent ac99a59 commit 3db7c2e
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.List;
import java.util.Objects;
@@ -98,7 +99,15 @@ private void load() {

try {
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<>();
InetAddress local = null;

0 comments on commit 3db7c2e

Please sign in to comment.