提交 d18d1e10 authored 作者: thomasmueller's avatar thomasmueller

On Mac OS X, with IPv6 and no network connection, the Console tool was not working as expected.

上级 06023b7a
...@@ -35,6 +35,8 @@ Change Log ...@@ -35,6 +35,8 @@ Change Log
</li> </li>
<li>Issue #479: Allow non-recursive Common Table Expressions (CTE) <li>Issue #479: Allow non-recursive Common Table Expressions (CTE)
</li> </li>
<li>On Mac OS X, with IPv6 and no network connection, the Console tool was not working as expected.
</li>
</ul> </ul>
<h2>Version 1.4.195 (2017-04-23)</h2> <h2>Version 1.4.195 (2017-04-23)</h2>
......
...@@ -44,12 +44,9 @@ public class NetUtils { ...@@ -44,12 +44,9 @@ public class NetUtils {
*/ */
public static Socket createLoopbackSocket(int port, boolean ssl) public static Socket createLoopbackSocket(int port, boolean ssl)
throws IOException { throws IOException {
InetAddress address = getBindAddress(); String local = getLocalAddress();
if (address == null) {
address = InetAddress.getLocalHost();
}
try { try {
return createSocket(getHostAddress(address), port, ssl); return createSocket(local, port, ssl);
} catch (IOException e) { } catch (IOException e) {
try { try {
return createSocket("localhost", port, ssl); return createSocket("localhost", port, ssl);
...@@ -60,23 +57,6 @@ public class NetUtils { ...@@ -60,23 +57,6 @@ public class NetUtils {
} }
} }
/**
* Get the host address. This method adds '[' and ']' if required for
* Inet6Address that contain a ':'.
*
* @param address the address
* @return the host address
*/
private static String getHostAddress(InetAddress address) {
String host = address.getHostAddress();
if (address instanceof Inet6Address) {
if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
host = "[" + host + "]";
}
}
return host;
}
/** /**
* Create a client socket that is connected to the given address and port. * Create a client socket that is connected to the given address and port.
* *
...@@ -274,7 +254,21 @@ public class NetUtils { ...@@ -274,7 +254,21 @@ public class NetUtils {
throw DbException.convert(e); throw DbException.convert(e);
} }
} }
String address = bind == null ? "localhost" : getHostAddress(bind); String address;
if (bind == null) {
address = "localhost";
} else {
address = bind.getHostAddress();
if (bind instanceof Inet6Address) {
if (address.indexOf("%") >= 0) {
address = "localhost";
} else if (address.indexOf(':') >= 0 && !address.startsWith("[")) {
// adds'[' and ']' if required for
// Inet6Address that contain a ':'.
address = "[" + address + "]";
}
}
}
if (address.equals("127.0.0.1")) { if (address.equals("127.0.0.1")) {
address = "localhost"; address = "localhost";
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论