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 16, 2024
1 parent 5e222b3 commit 9afa991
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/server/kiwix-serve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,18 +324,12 @@ 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 :
kiwix::IpMode::ipv4;

if (address == "ipv4" || address == "ipv6" || address == "all") // Protocol has been provided instead of ip. Clear it since it has been handled.
address.clear();

#ifndef _WIN32
/* Fork if necessary */
Expand Down Expand Up @@ -367,8 +361,13 @@ int main(int argc, char** argv)
exit(1);
}
}

<<<<<<< HEAD
// if ip not protocol -- if includes '.'
server.setAddress(address);
=======

// server.setAddress{x.x.x.x};
>>>>>>> a322878 (kiwix-serve displays both protocol attached ips)
server.setRoot(rootLocation);
server.setPort(serverPort);
server.setNbThreads(nb_threads);
Expand All @@ -384,12 +383,14 @@ 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://";
std::vector<std::string> addresses = server.getAddresses();
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: ";
if(addresses.size() == 2)
std::cout << prefix << addresses[0] << suffix << " and " << prefix << addresses[1] << suffix << std::endl;
else
std::cout << prefix << addresses[0] << suffix << std::endl;

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

0 comments on commit 9afa991

Please sign in to comment.