Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

more IPv6 hacks

Michael Peter Christen358b04885e49
diff --git a/source/net/yacy/cora/document/MultiProtocolURI.java b/source/net/yacy/cora/document/MultiProtocolURI.java
index 05fc2580b..24592ee2d 100644
--- a/source/net/yacy/cora/document/MultiProtocolURI.java
+++ b/source/net/yacy/cora/document/MultiProtocolURI.java
@@ -349,8 +349,9 @@ public class MultiProtocolURI implements Serializable, Comparable<MultiProtocolU
escape();
}
- public MultiProtocolURI(final String protocol, final String host, final int port, final String path) throws MalformedURLException {
+ public MultiProtocolURI(final String protocol, String host, final int port, final String path) throws MalformedURLException {
if (protocol == null) throw new MalformedURLException("protocol is null");
+ if (host.indexOf(':') >= 0 && host.charAt(0) != '[') host = '[' + host + ']'; // IPv6 host must be enclosed in square brackets
this.protocol = protocol;
this.host = host;
this.port = port;
@@ -709,7 +710,7 @@ public class MultiProtocolURI implements Serializable, Comparable<MultiProtocolU
}
public String getHost() {
- return this.host;
+ return (this.host.charAt(0) == '[' && this.host.charAt(this.host.length() - 1) == ']') ? this.host.substring(1, this.host.length() - 1) : this.host;
}
public String getTLD() {
diff --git a/source/net/yacy/cora/protocol/Domains.java b/source/net/yacy/cora/protocol/Domains.java
index d47a299cc..d0ee78b7c 100644
--- a/source/net/yacy/cora/protocol/Domains.java
+++ b/source/net/yacy/cora/protocol/Domains.java
@@ -570,7 +570,7 @@ public class Domains {
* @return the hosts InetAddress or null if the address cannot be resolved
*/
public static InetAddress dnsResolve(final String host0) {
- if ((host0 == null) || (host0.length() == 0)) return null;
+ if (host0 == null || host0.length() == 0) return null;
final String host = host0.toLowerCase().trim();
// try to simply parse the address
InetAddress ip = parseInetAddress(host);
@@ -689,7 +689,9 @@ public class Domains {
public static final InetAddress parseInetAddress(String ip) {
if (ip == null || ip.length() < 8) return null;
- if (isLocalhost(ip)) ip = LOCALHOST;
+ ip = ip.trim();
+ if (ip.charAt(0) == '[' && ip.charAt(ip.length() - 1) == ']') ip = ip.substring(1, ip.length() - 1);
+ if (isLocalhost(ip)) ip = "127.0.0.1"; // normalize to IPv4 here since that is the way to calculate the InetAddress
final String[] ips = dotPattern.split(ip);
if (ips.length != 4) return null;
final byte[] ipb = new byte[4];