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 29b6255 commit ec22d26
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/server/internalServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ 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 @@ -484,6 +497,11 @@ bool InternalServer::start() {
return false;
}

if (!ipAvailable(addr)) {
std::cerr << "ERROR: IP address is not available on this system: " << addr << std::endl;
return false;
}

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

Expand Down

0 comments on commit ec22d26

Please sign in to comment.