From 6090e95cdcea7c0600ea75941289494505295cf2 Mon Sep 17 00:00:00 2001 From: Kahrl Date: Fri, 7 Mar 2014 01:00:03 +0100 Subject: Infer ipv6_server from bind_address; fix client connect to IN(6)ADDR_ANY --- src/game.cpp | 63 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 27 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index 7d881fa88..f435a4d71 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1147,28 +1147,35 @@ void the_game(bool &kill, bool random_input, InputHandler *input, draw_load_screen(text, device, font,0,25); delete[] text; infostream<<"Creating server"<get("bind_address"); Address bind_addr(0,0,0,0, port); - if (bind_str != "") - { - try { - bind_addr.Resolve(bind_str.c_str()); - address = bind_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); + } + try { + bind_addr.Resolve(bind_str.c_str()); + address = bind_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); - } - } + if(bind_addr.isIPv6() && !g_settings->getBool("enable_ipv6")) { + error_message = L"Unable to listen on " + + narrow_to_wide(bind_addr.serializeString()) + + L" because IPv6 is disabled"; + errorstream<start(bind_addr); } @@ -1193,31 +1200,33 @@ void the_game(bool &kill, bool random_input, InputHandler *input, delete[] text; } Address connect_address(0,0,0,0, port); - try{ - if(address == "") - { + try { + connect_address.Resolve(address.c_str()); + if (connect_address.isZero()) { // i.e. INADDR_ANY, IN6ADDR_ANY //connect_address.Resolve("localhost"); - if(g_settings->getBool("enable_ipv6") && g_settings->getBool("ipv6_server")) - { + if (connect_address.isIPv6()) { IPv6AddressBytes addr_bytes; addr_bytes.bytes[15] = 1; connect_address.setAddress(&addr_bytes); - } - else - { + } else { connect_address.setAddress(127,0,0,1); } } - else - connect_address.Resolve(address.c_str()); } - catch(ResolveError &e) - { + catch(ResolveError &e) { error_message = L"Couldn't resolve address: " + narrow_to_wide(e.what()); errorstream<getBool("enable_ipv6")) { + error_message = L"Unable to connect to " + + narrow_to_wide(connect_address.serializeString()) + + L" because IPv6 is disabled"; + errorstream<