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 Sep 28, 2024
1 parent 316f713 commit a29ac6a
Show file tree
Hide file tree
Showing 2 changed files with 19 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 @@ -1311,3 +1311,21 @@ std::unique_ptr<Response> InternalServer::handle_locally_customized_resource(con
}

}

bool ipAvailable(const kiwix::IpAddress& addr, const kiwix::IpMode& mode)
{
bool validV4 = false, validV6 = false;
auto interfaces = kiwix::getNetworkInterfacesIPv4Or6();
std::cout << "Address provided: " << addr.addr << " | " << addr.addr6 << std::endl;
for (const auto& interface : interfaces) {
kiwix::IpAddress interfaceIps = interface.second;
std::cout << "Interface: " << interface.first << " " << interfaceIps.addr << " " << interfaceIps.addr6 << std::endl;
validV4 |= !validV4 && interfaceIps.addr == addr.addr;
validV6 |= !validV6 && interfaceIps.addr6 == addr.addr6;
}

if (mode == kiwix::IpMode::IPV4) return validV4;
else if (mode == kiwix::IpMode::IPV6) return validV6;

return validV4 && validV6;
}
1 change: 1 addition & 0 deletions src/server/internalServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,5 @@ class InternalServer {

}

bool ipAvailable(const kiwix::IpAddress& addr, const kiwix::IpMode& mode);
#endif //KIWIXLIB_SERVER_INTERNALSERVER_H

0 comments on commit a29ac6a

Please sign in to comment.