This is an automated email from the ASF dual-hosted git repository.

dsoumis pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
     new d2ca4803e8 Stabilize TestStartupIPv6Connectors IPv6 selection
d2ca4803e8 is described below

commit d2ca4803e814b7940e4a5c0ad9400a4b1ec62c15
Author: Dimitris Soumis <[email protected]>
AuthorDate: Wed Nov 12 13:38:55 2025 +0200

    Stabilize TestStartupIPv6Connectors IPv6 selection
---
 .../startup/TestStartupIPv6Connectors.java         | 48 ++++++++++++++++++----
 1 file changed, 40 insertions(+), 8 deletions(-)

diff --git a/test/org/apache/catalina/startup/TestStartupIPv6Connectors.java 
b/test/org/apache/catalina/startup/TestStartupIPv6Connectors.java
index 6802917a0e..cc4e280acc 100644
--- a/test/org/apache/catalina/startup/TestStartupIPv6Connectors.java
+++ b/test/org/apache/catalina/startup/TestStartupIPv6Connectors.java
@@ -64,29 +64,61 @@ public class TestStartupIPv6Connectors extends 
TomcatBaseTest {
 
     @BeforeClass
     public static void initializeTestIpv6Addresses() throws Exception {
+        Inet6Address possibleLinkLocalLoopback = null;
+        Inet6Address possibleLinkLocalOnGlobal = null;
+        Inet6Address possibleLinkLocalAny = null;
+
         Enumeration<NetworkInterface> interfaces = 
NetworkInterface.getNetworkInterfaces();
         while (interfaces.hasMoreElements()) {
             NetworkInterface interf = interfaces.nextElement();
-            Enumeration<InetAddress> addresses = interf.getInetAddresses();
-            if (interf.isPointToPoint()) {
+            if (!interf.isUp() || interf.isVirtual() || 
interf.isPointToPoint() || !interf.supportsMulticast()) {
                 continue;
             }
+            Enumeration<InetAddress> addresses = interf.getInetAddresses();
+            boolean globalOnInterface = false;
             while (addresses.hasMoreElements()) {
                 InetAddress address = addresses.nextElement();
                 if (address instanceof Inet6Address) {
                     Inet6Address inet6Address = (Inet6Address) address;
-                    if (inet6Address.isLinkLocalAddress()) {
-                        linklocalAddress = inet6Address.getHostAddress();
-                    }
                     if (!inet6Address.isAnyLocalAddress() && 
!inet6Address.isLoopbackAddress() && !inet6Address.isLinkLocalAddress() && 
!inet6Address.isMulticastAddress()) {
-                        globalAddress = inet6Address.getHostAddress();
+                        globalOnInterface = true;
+                        if (!interf.isLoopback()) {
+                            globalAddress = inet6Address.getHostAddress();
+                            break;
+                        }
                     }
-                    if (linklocalAddress != null && globalAddress != null) {
-                        return;
+                }
+            }
+
+            // Second pass to get link-local results with specific order
+            addresses = interf.getInetAddresses();
+            while (addresses.hasMoreElements()) {
+                InetAddress address = addresses.nextElement();
+                if (address instanceof Inet6Address) {
+                    Inet6Address inet6Address = (Inet6Address) address;
+                    if (inet6Address.isLinkLocalAddress()) {
+                        if (interf.isLoopback()) {
+                            // Best option for mac
+                            possibleLinkLocalLoopback = inet6Address;
+                        } else if (globalOnInterface && 
possibleLinkLocalOnGlobal == null) {
+                            // link-local on an interface that also has a 
global IPv6 (e.g. en0)
+                            possibleLinkLocalOnGlobal = inet6Address;
+                        } else if (possibleLinkLocalAny == null) {
+                            possibleLinkLocalAny = inet6Address;
+                        }
                     }
                 }
             }
         }
+
+        if (possibleLinkLocalLoopback != null) {
+            linklocalAddress = possibleLinkLocalLoopback.getHostAddress();
+        } else if (possibleLinkLocalOnGlobal != null) {
+            linklocalAddress = possibleLinkLocalOnGlobal.getHostAddress();
+        } else if (possibleLinkLocalAny != null) {
+            linklocalAddress = possibleLinkLocalAny.getHostAddress();
+        }
+
     }
 
     private void assertHttpOkOnAddress(String address) throws Exception {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to