used os::host_ips()

This commit is contained in:
Kevin Darby committed 2019-06-10 15:57:53 -04:00
1 parent 95a5791867
commit 62c7886807
2 files changed
+14 -68

No files matched your search

+5 -30
View File
@@ -7,6 +7,7 @@
#include "lib/utils/crypto/PublicKey.h"
#include "lib/utils/crypto/KeyCodeHelper.h"
#include "lib/logging/logging.h"
#include "lib/os/os.h"
#include "lib/utils/bts_assert.h"
#include "lib/utils/helper_macros.h"
#include "lib/config/config.h"
@@ -57,36 +58,10 @@ std::string KeyCode::helpstr ()
int checkips()
{
struct ifaddrs * ifAddrStruct=NULL;
struct ifaddrs * ifa=NULL;
void * tmpAddrPtr=NULL;
getifaddrs(&ifAddrStruct);
for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next)
{
if (!ifa->ifa_addr)
continue;
if (ifa->ifa_addr->sa_family == AF_INET) // check it is IP4
{
// is a valid IP4 Address
tmpAddrPtr=&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
char addressBuffer[INET_ADDRSTRLEN];
inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN);
printf("%s IP Address => %s\n", ifa->ifa_name, addressBuffer);
}
else if (ifa->ifa_addr->sa_family == AF_INET6) // check it is IP6
{
// is a valid IP6 Address
tmpAddrPtr=&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
char addressBuffer[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, tmpAddrPtr, addressBuffer, INET6_ADDRSTRLEN);
printf("%s IP Address => %s\n", ifa->ifa_name, addressBuffer);
}
}
if (ifAddrStruct!=NULL)
freeifaddrs(ifAddrStruct);
return 0;
auto ipmap = bts::os::host_ips();
for(const auto& x: ipmap)
std::cout << x.first << " => " << x.second << std::endl;
return 0;
}
std::string parse_date (std::string const &date)