diff --git a/RouterContext.cpp b/RouterContext.cpp index f61aaed8..737a92fc 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -51,7 +51,16 @@ namespace i2p port = rand () % (30777 - 9111) + 9111; // I2P network ports range bool ipv4; i2p::config::GetOption("ipv4", ipv4); bool ipv6; i2p::config::GetOption("ipv6", ipv6); - std::string host = i2p::util::config::GetHost(ipv4, ipv6); + bool nat; i2p::config::GetOption("nat", nat); + std::string ifname; i2p::config::GetOption("ifname", ifname); + std::string host = ipv6 ? "::" : "127.0.0.1"; + if (nat) { + if (!i2p::config::IsDefault("host")) + i2p::config::GetOption("host", host); + } else if (!ifname.empty()) { + /* bind to interface, we have no NAT so set external address too */ + host = i2p::util::net::GetInterfaceAddress(ifname, ipv6).to_string(); + } routerInfo.AddSSUAddress (host.c_str(), port, routerInfo.GetIdentHash ()); routerInfo.AddNTCPAddress (host.c_str(), port); routerInfo.SetCaps (i2p::data::RouterInfo::eReachable | diff --git a/util.cpp b/util.cpp index 5913d9a7..08ee6672 100644 --- a/util.cpp +++ b/util.cpp @@ -7,7 +7,6 @@ #include #include #include -#include "Config.h" #include "util.h" #include "Log.h" @@ -460,31 +459,5 @@ namespace net #endif } } - -namespace config -{ - std::string GetHost(bool ipv4, bool ipv6) - { - std::string host; - if(ipv6) - host = "::"; - else if(ipv4) - host = "127.0.0.1"; - bool nat; i2p::config::GetOption("nat", nat); - if (nat) - { - if (!i2p::config::IsDefault("host")) - i2p::config::GetOption("host", host); - } - else - { - // we are not behind nat - std::string ifname; i2p::config::GetOption("ifname", ifname); - if (ifname.size()) - host = i2p::util::net::GetInterfaceAddress(ifname, ipv6).to_string(); // bind to interface, we have no NAT so set external address too - } - return host; - } -} // config } // util } // i2p diff --git a/util.h b/util.h index 8995f12b..642ecc9b 100644 --- a/util.h +++ b/util.h @@ -68,14 +68,7 @@ namespace util int GetMTU (const boost::asio::ip::address& localAddress); const boost::asio::ip::address GetInterfaceAddress(const std::string & ifname, bool ipv6=false); } - - namespace config - { - /** get the host to use from out config, for use in RouterContext.cpp */ - std::string GetHost(bool ipv4=true, bool ipv6=true); - } } } - #endif