more IPv6 hacks

pull/1/head
Michael Peter Christen 13 years ago
parent 96aeb127e3
commit 358b04885e

@ -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() {

@ -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];

Loading…
Cancel
Save