提交 fc876e01 authored 作者: Thomas Mueller's avatar Thomas Mueller

Auto-server mode: the host name is now stored in the .lock.db file.

上级 1d3cb4a6
......@@ -778,8 +778,11 @@ public class Database implements DataHandler {
} catch (SQLException e) {
throw DbException.convert(e);
}
String address = NetUtils.getLocalAddress() + ":" + server.getPort();
String localAddress = NetUtils.getLocalAddress();
String address = localAddress + ":" + server.getPort();
lock.setProperty("server", address);
String hostName = NetUtils.getHostName(localAddress);
lock.setProperty("hostName", hostName);
lock.save();
}
......
......@@ -277,4 +277,19 @@ public class NetUtils {
return address;
}
/**
* Get the host name of a local address, if available.
*
* @param localAddress the local address
* @return the host name, or another text if not available
*/
public static String getHostName(String localAddress) {
try {
InetAddress addr = InetAddress.getByName(localAddress);
return addr.getHostName();
} catch (Exception e) {
return "unknown";
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论