liudezhi2098 commented on a change in pull request #2240: fix the problem that
the method InetAddress.getLocalHost().getHostAddress() gets ip as 127.0.0.1
URL: https://github.com/apache/bookkeeper/pull/2240#discussion_r375217551
##########
File path:
bookkeeper-server/src/main/java/org/apache/bookkeeper/net/NetUtils.java
##########
@@ -85,4 +85,52 @@ public static String
resolveNetworkLocation(DNSToSwitchMapping dnsResolver, Inet
return rNames.get(0);
}
+ public static String getLocalHost() throws UnknownHostException {
+ try {
+ String ip = InetAddress.getLocalHost().getHostAddress();
+ if (ip.equals("127.0.0.1")) {
+ return getAddress();
+ } else
+ return ip;
+ } catch (Throwable e) {
+ String ip = getAddress();
+ if (ip != null && !ip.isEmpty()) {
+ return ip;
+ }
+ throw new UnknownHostException("InetAddress
java.net.InetAddress.getLocalHost() throws UnknownHostException,"
+ + e.getMessage());
+ }
+ }
+
+ private static boolean isboolIp(String ipAddress) {
+ String ip =
"([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}";
+ Pattern pattern = Pattern.compile(ip);
Review comment:
sorry, already change
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services