Skip to content

Commit 7047df7

Browse files
authored
Made webserver binding logging less confusing (#474)
People often think "0.0.0.0" is the IP they should connect to when BlueMap logs `WebServer bound to: /0.0.0.0:8100` Or they see the IPv6 address being logged, and think BlueMap is only running on IPv6.
1 parent c407ba6 commit 7047df7

File tree

1 file changed

+16
-1
lines changed
  • BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/http

1 file changed

+16
-1
lines changed

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/http/Server.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828

2929
import java.io.Closeable;
3030
import java.io.IOException;
31+
import java.net.InetSocketAddress;
3132
import java.net.SocketAddress;
3233
import java.nio.channels.*;
3334
import java.util.ArrayList;
3435
import java.util.Collection;
36+
import java.util.Objects;
3537

3638
public abstract class Server extends Thread implements Closeable, Runnable {
3739

@@ -52,7 +54,20 @@ public void bind(SocketAddress address) throws IOException {
5254
server.bind(address);
5355
this.server.add(server);
5456

55-
Logger.global.logInfo("WebServer bound to: " + server.getLocalAddress());
57+
if (checkIfBoundToAllInterfaces(address)) {
58+
Logger.global.logInfo("WebServer bound to all network interfaces on port " + ((InetSocketAddress) address).getPort());
59+
} else {
60+
Logger.global.logInfo("WebServer bound to: " + server.getLocalAddress());
61+
}
62+
}
63+
64+
private boolean checkIfBoundToAllInterfaces(SocketAddress address) {
65+
if (address instanceof InetSocketAddress) {
66+
InetSocketAddress inetAddress = (InetSocketAddress) address;
67+
return Objects.equals(inetAddress.getAddress(), new InetSocketAddress(0).getAddress());
68+
}
69+
70+
return false;
5671
}
5772

5873
@Override

0 commit comments

Comments
 (0)