Skip to content

Commit 995e26f

Browse files
committed
fix: improve getLocalHostLANAddresses() for IPv6
1 parent 8d076a3 commit 995e26f

File tree

1 file changed

+19
-3
lines changed
  • modules/kernel/src/org/apache/axis2/util

1 file changed

+19
-3
lines changed

modules/kernel/src/org/apache/axis2/util/Utils.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
import java.lang.reflect.InvocationTargetException;
6262
import java.lang.reflect.Method;
6363
import java.lang.reflect.Modifier;
64+
import java.net.Inet4Address;
65+
import java.net.Inet6Address;
6466
import java.net.InetAddress;
6567
import java.net.NetworkInterface;
6668
import java.net.SocketException;
@@ -607,11 +609,25 @@ public static List<InetAddress> getLocalHostLANAddresses() throws SocketExceptio
607609
final InetAddress inetAddr = inetAddrs.nextElement();
608610
if ( !inetAddr.isLoopbackAddress() )
609611
{
610-
if (inetAddr.isSiteLocalAddress())
612+
if (!inetAddr.isLinkLocalAddress())
611613
{
612-
// Found non-loopback site-local address.
613-
addresses.add(inetAddr);
614+
if (inetAddr instanceof Inet6Address) {
615+
Inet6Address inet6Addr = (Inet6Address) inetAddr;
616+
if ((inet6Addr.getAddress()[0] ^ 0xfc) > 1)
617+
{
618+
// we ignore the site-local attribute for IPv6 because
619+
// it has been deprecated, see https://www.ietf.org/rfc/rfc3879.txt
620+
// instead we verify that this is not a unique local address,
621+
// this check is unfortunately not in the standard library (yet)
622+
// https://en.wikipedia.org/wiki/Unique_local_address
623+
addresses.add(inetAddr);
624+
}
625+
} else if (inetAddr instanceof Inet4Address && inetAddr.isSiteLocalAddress()) {
626+
// check site-local
627+
addresses.add(inetAddr);
628+
}
614629
}
630+
615631
if ( candidateAddress == null )
616632
{
617633
// Found non-loopback address, but not necessarily site-local.

0 commit comments

Comments
 (0)