From 21e84539e80709a16d5d731b3ff78a6a4dcf9064 Mon Sep 17 00:00:00 2001 From: orbiter Date: Mon, 29 Nov 2010 19:49:57 +0000 Subject: [PATCH] one more fix to Domains git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7353 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/net/yacy/cora/protocol/Domains.java | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/source/net/yacy/cora/protocol/Domains.java b/source/net/yacy/cora/protocol/Domains.java index 5919bb463..9b3bcbcb6 100644 --- a/source/net/yacy/cora/protocol/Domains.java +++ b/source/net/yacy/cora/protocol/Domains.java @@ -642,13 +642,22 @@ public class Domains { (a.getHostAddress().indexOf(":") < 0)) return a; } - // there is only a local address, we filter out the possibly - // returned loopback address 127.0.0.1 and all addresses without a name + // there is only a local address + // return that one that is returned with InetAddress.getLocalHost() + // if appropriate + try { + InetAddress localHostAddress = InetAddress.getLocalHost(); + if (localHostAddress != null && + (0Xff & localHostAddress.getAddress()[0]) != 127 && + localHostAddress.getHostAddress().indexOf(":") < 0) return localHostAddress; + } catch (UnknownHostException e) { + } + // we filter out the loopback address 127.0.0.1 and all addresses without a name for (InetAddress a: localHostAddresses) { if ((0Xff & a.getAddress()[0]) != 127 && a.getHostAddress().indexOf(":") < 0 && a.getHostName() != null && - a.getCanonicalHostName().length() > 0) return a; + a.getHostName().length() > 0) return a; } // if no address has a name, then take any other than the loopback for (InetAddress a: localHostAddresses) { @@ -669,12 +678,9 @@ public class Domains { */ public static List myIntranetIPs() { // list all local addresses - if (localHostAddresses.size() < 2) try {Thread.sleep(1000);} catch (InterruptedException e) {} + if (localHostAddresses.size() < 1) try {Thread.sleep(1000);} catch (InterruptedException e) {} ArrayList list = new ArrayList(localHostAddresses.size()); - if (localHostAddresses.size() == 0) { - // give up - return list; - } + if (localHostAddresses.size() == 0) return list; // give up for (InetAddress a: localHostAddresses) { if ((0Xff & a.getAddress()[0]) == 127) continue; if (!matchesList(a.getHostAddress(), localhostPatterns)) continue; @@ -690,9 +696,7 @@ public class Domains { try { final InetAddress clientAddress = Domains.dnsResolve(hostName); if (clientAddress == null) return false; - if (clientAddress.isAnyLocalAddress() || clientAddress.isLoopbackAddress()) return true; - for (InetAddress a: localHostAddresses) { if (a.equals(clientAddress)) { isThisHostIP = true; @@ -779,7 +783,7 @@ public class Domains { System.err.println(e); } */ - + try { Thread.sleep(1000);} catch (InterruptedException e) {} // get time for class init System.out.println("myPublicLocalIP: " + myPublicLocalIP()); for (InetAddress a : myIntranetIPs()) { System.out.println("Intranet IP: " + a);