From 85fe75d1cbaf372f0a98558adcd5a612a0e19602 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Wed, 5 Feb 2014 21:24:46 +0100 Subject: Add the option to bind to a specific address --- src/main.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 8186e26c8..b5de4b93f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1024,6 +1024,21 @@ int main(int argc, char *argv[]) if(port == 0) port = 30000; + // Bind address + std::string bind_str = g_settings->get("bind_address"); + Address bind_addr(0,0,0,0, port); + try { + bind_addr.Resolve(bind_str.c_str()); + } catch (ResolveError &e) { + infostream << "Resolving bind address \"" << bind_str + << "\" failed: " << e.what() + << " -- Listening on all addresses." << std::endl; + + if (g_settings->getBool("ipv6_server")) { + bind_addr.setAddress((IPv6AddressBytes*) NULL); + } + } + // World directory std::string commanded_world = ""; if(cmd_args.exists("world")) @@ -1270,7 +1285,7 @@ int main(int argc, char *argv[]) return 0; } - server.start(port); + server.start(bind_addr); // Run server dedicated_server_loop(server, kill); -- cgit v1.2.3