Skip to content

Commit

Permalink
Add ip availability check in server start
Browse files Browse the repository at this point in the history
  • Loading branch information
sgourdas committed Oct 2, 2024
1 parent e6d488b commit d71a005
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/server/internalServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ namespace kiwix {
namespace
{

bool ipAvailable(const std::string addr)
{
auto interfaces = kiwix::getNetworkInterfacesIPv4Or6();

for (const auto& [_, interfaceIps] : interfaces)
if ((interfaceIps.addr == addr) || (interfaceIps.addr6 == addr)) return true;

return false;
}

inline std::string normalizeRootUrl(std::string rootUrl)
{
while ( !rootUrl.empty() && rootUrl.back() == '/' )
Expand Down Expand Up @@ -483,6 +493,10 @@ bool InternalServer::start() {
std::cerr << "IP address " << addr << " is not a valid ip address." << std::endl;
return false;
}
if (!ipAvailable(addr)) {
std::cerr << "IP address " << addr << " is not available on this system." << std::endl;
return false;
}

m_ipMode = !m_addr.addr.empty() ? IpMode::IPV4 : IpMode::IPV6;
}
Expand Down

0 comments on commit d71a005

Please sign in to comment.