Skip to content

Commit

Permalink
kiwix-serve displays both protocol attached ips
Browse files Browse the repository at this point in the history
  • Loading branch information
sgourdas committed Sep 28, 2024
1 parent c6b72e9 commit 7c2418a
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/server/kiwix-serve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,13 @@ int main(int argc, char** argv)
auto libraryFileTimestamp = newestFileTimestamp(libraryPaths);
auto curLibraryFileTimestamp = libraryFileTimestamp;

/* Infer ipMode from address */
kiwix::IpMode ipMode = kiwix::IpMode::ipv4;

if (address == "all"){
address = "";
ipMode = kiwix::IpMode::all;
} else if (address == "ipv4"){
address = "";
} else if (address == "ipv6"){
address = "";
ipMode = kiwix::IpMode::ipv6;
kiwix::IpMode ipMode = (address == "all") ? kiwix::IpMode::ALL :
(address == "ipv6") ? kiwix::IpMode::IPV6 :
(address == "ipv4") ? kiwix::IpMode::IPV4 :
kiwix::IpMode::FLEX;

if(!address.empty() && ipMode != kiwix::IpMode::FLEX) {
address.clear(); // Clear to indicate that protocol has been provided in address.
}

#ifndef _WIN32
Expand Down Expand Up @@ -384,12 +380,12 @@ int main(int argc, char** argv)
exit(1);
}

std::string host = (server.getIpMode()==kiwix::IpMode::all || server.getIpMode()==kiwix::IpMode::ipv6)
? "[" + server.getAddress() + "]" : server.getAddress();

std::string url = "http://" + host + ":" + std::to_string(server.getPort()) + normalizeRootUrl(rootLocation);
std::cout << "The Kiwix server is running and can be accessed in the local network at: "
<< url << std::endl;
std::string prefix = "http://";
kiwix::IpAddress addresses = server.getAddress();
std::string suffix = ":" + std::to_string(server.getPort()) + normalizeRootUrl(rootLocation);
std::cout << "The Kiwix server is running and can be accessed in the local network at: " << std::endl;
if(!addresses.addr.empty()) std::cout << " - " << prefix << addresses.addr << suffix << std::endl;
if(!addresses.addr6.empty()) std::cout << " - " << prefix << "[" << addresses.addr6 << "]" << suffix << std::endl;

/* Run endless (until PPID dies) */
waiting = true;
Expand Down

0 comments on commit 7c2418a

Please sign in to comment.