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 b806999 commit 95529d2
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;

Check warning on line 98 in src/server/internalServer.cpp

View check run for this annotation

Codecov / codecov/patch

src/server/internalServer.cpp#L98

Added line #L98 was not covered by tests
}

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;

Check warning on line 497 in src/server/internalServer.cpp

View check run for this annotation

Codecov / codecov/patch

src/server/internalServer.cpp#L497

Added line #L497 was not covered by tests
}

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 95529d2

Please sign in to comment.