This is an automated email from the ASF dual-hosted git repository.
pandaapo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new a1fce2f6a [ISSUE #4654]Get Ip address problem when run example code
(#4655)
a1fce2f6a is described below
commit a1fce2f6a1d36f61113f11f97f3665d008ab7a9c
Author: Karson <[email protected]>
AuthorDate: Mon Jan 8 17:31:50 2024 +0800
[ISSUE #4654]Get Ip address problem when run example code (#4655)
* fix bug for mac get ip address
* reformat code style
* rename parameter
* some enhance
* some enhance
---
.../src/main/java/org/apache/eventmesh/common/utils/IPUtils.java | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git
a/eventmesh-common/src/main/java/org/apache/eventmesh/common/utils/IPUtils.java
b/eventmesh-common/src/main/java/org/apache/eventmesh/common/utils/IPUtils.java
index 674e8a402..f22389ffd 100644
---
a/eventmesh-common/src/main/java/org/apache/eventmesh/common/utils/IPUtils.java
+++
b/eventmesh-common/src/main/java/org/apache/eventmesh/common/utils/IPUtils.java
@@ -59,14 +59,19 @@ public class IPUtils {
List<String> list = Arrays.asList(priority.split("<"));
ArrayList<String> preferList = new ArrayList<>(list);
NetworkInterface preferNetworkInterface = null;
+ boolean isInterfacePreferred = false;
try {
Enumeration<NetworkInterface> enumeration1 =
NetworkInterface.getNetworkInterfaces();
while (enumeration1.hasMoreElements()) {
final NetworkInterface networkInterface =
enumeration1.nextElement();
+ String interfaceName = networkInterface.getName();
+ if (!isInterfacePreferred &&
preferList.contains(interfaceName)) {
+ isInterfacePreferred = true;
+ }
if (preferNetworkInterface == null) {
preferNetworkInterface = networkInterface;
- } else if (preferList.indexOf(networkInterface.getName()) //
get the networkInterface that has higher priority
+ } else if (preferList.indexOf(interfaceName) // get the
networkInterface that has higher priority
> preferList.indexOf(preferNetworkInterface.getName())) {
preferNetworkInterface = networkInterface;
}
@@ -76,7 +81,7 @@ public class IPUtils {
ArrayList<String> ipv4Result = new ArrayList<String>();
ArrayList<String> ipv6Result = new ArrayList<String>();
- if (preferNetworkInterface != null) {
+ if (preferNetworkInterface != null && isInterfacePreferred) {
final Enumeration<InetAddress> en =
preferNetworkInterface.getInetAddresses();
getIpResult(ipv4Result, ipv6Result, en);
} else {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]