|
61 | 61 | import java.lang.reflect.InvocationTargetException; |
62 | 62 | import java.lang.reflect.Method; |
63 | 63 | import java.lang.reflect.Modifier; |
| 64 | +import java.net.Inet4Address; |
| 65 | +import java.net.Inet6Address; |
64 | 66 | import java.net.InetAddress; |
65 | 67 | import java.net.NetworkInterface; |
66 | 68 | import java.net.SocketException; |
@@ -607,11 +609,25 @@ public static List<InetAddress> getLocalHostLANAddresses() throws SocketExceptio |
607 | 609 | final InetAddress inetAddr = inetAddrs.nextElement(); |
608 | 610 | if ( !inetAddr.isLoopbackAddress() ) |
609 | 611 | { |
610 | | - if (inetAddr.isSiteLocalAddress()) |
| 612 | + if (!inetAddr.isLinkLocalAddress()) |
611 | 613 | { |
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 | + } |
614 | 629 | } |
| 630 | + |
615 | 631 | if ( candidateAddress == null ) |
616 | 632 | { |
617 | 633 | // Found non-loopback address, but not necessarily site-local. |
|
0 commit comments