mirror of https://github.com/kiwix/libkiwix.git
kiwix::getNetworkInterfacesIPv4Or6()
- Restored kiwix::getNetworkInterfaces() API to the version before support for IPv6 was introduced - Renamed the new API method to kiwix::getNetworkInterfacesIPv4Or6()
This commit is contained in:
parent
135c6f875d
commit
5927550a36
|
@ -25,10 +25,13 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace kiwix {
|
namespace kiwix
|
||||||
struct IpAddress{
|
{
|
||||||
std::string addr;
|
|
||||||
std::string addr6;
|
struct IpAddress
|
||||||
|
{
|
||||||
|
std::string addr; // IPv4 address
|
||||||
|
std::string addr6; // IPv6 address
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::pair<std::string, std::string> LangNameCodePair;
|
typedef std::pair<std::string, std::string> LangNameCodePair;
|
||||||
|
@ -223,11 +226,21 @@ std::string getMimeTypeForFile(const std::string& filename);
|
||||||
/** Provides all available network interfaces
|
/** Provides all available network interfaces
|
||||||
*
|
*
|
||||||
* This function provides the available IPv4 and IPv6 network interfaces
|
* This function provides the available IPv4 and IPv6 network interfaces
|
||||||
|
* as a map from the interface name to its IPv4 and/or IPv6 address(es).
|
||||||
*/
|
*/
|
||||||
std::map<std::string,IpAddress> getNetworkInterfaces();
|
std::map<std::string, IpAddress> getNetworkInterfacesIPv4Or6();
|
||||||
|
|
||||||
|
/** Provides all available IPv4 network interfaces
|
||||||
|
*
|
||||||
|
* This function provides the available IPv4 network interfaces
|
||||||
|
* as a map from the interface name to its IPv4 address.
|
||||||
|
*
|
||||||
|
* Provided for backward compatibility with libkiwix v13.1.0.
|
||||||
|
*/
|
||||||
|
std::map<std::string, std::string> getNetworkInterfaces();
|
||||||
|
|
||||||
/** Provides the best IP address
|
/** Provides the best IP address
|
||||||
* This function provides the best IP address from the list given by getNetworkInterfaces
|
* This function provides the best IP address from the list given by getNetworkInterfacesIPv4Or6()
|
||||||
*/
|
*/
|
||||||
std::string getBestPublicIp(bool ipv6);
|
std::string getBestPublicIp(bool ipv6);
|
||||||
|
|
||||||
|
|
|
@ -191,7 +191,7 @@ std::map<std::string, IpAddress> getNetworkInterfacesPosix() {
|
||||||
|
|
||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
|
|
||||||
std::map<std::string, IpAddress> getNetworkInterfaces() {
|
std::map<std::string, IpAddress> getNetworkInterfacesIPv4Or6() {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return getNetworkInterfacesWin();
|
return getNetworkInterfacesWin();
|
||||||
#else
|
#else
|
||||||
|
@ -199,9 +199,22 @@ std::map<std::string, IpAddress> getNetworkInterfaces() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::string> getNetworkInterfaces() {
|
||||||
|
std::map<std::string, std::string> result;
|
||||||
|
for ( const auto& kv : getNetworkInterfacesIPv4Or6() ) {
|
||||||
|
const std::string& interfaceName = kv.first;
|
||||||
|
const auto& ipAddresses = kv.second;
|
||||||
|
if ( !ipAddresses.addr.empty() ) {
|
||||||
|
result[interfaceName] = ipAddresses.addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string getBestPublicIp(bool ipv6) {
|
std::string getBestPublicIp(bool ipv6) {
|
||||||
IpAddress bestPublicIp = IpAddress{"127.0.0.1","::1"};
|
IpAddress bestPublicIp = IpAddress{"127.0.0.1","::1"};
|
||||||
std::map<std::string, IpAddress> interfaces = getNetworkInterfaces();
|
std::map<std::string, IpAddress> interfaces = getNetworkInterfacesIPv4Or6();
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
const char* const prioritizedNames[] =
|
const char* const prioritizedNames[] =
|
||||||
|
|
Loading…
Reference in New Issue