format support lib

This commit is contained in:
Erik Frojdh
2020-05-05 10:07:19 +02:00
parent e599bb7c24
commit ea4044e4b1
38 changed files with 775 additions and 854 deletions

7
slsSupportLib/src/network_utils.cpp Executable file → Normal file
View File

@@ -1,5 +1,6 @@
#include "sls_detector_exceptions.h"
#include "network_utils.h"
#include <algorithm>
#include <arpa/inet.h>
#include <cassert>
@@ -15,7 +16,6 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include "network_utils.h"
namespace sls {
@@ -85,7 +85,8 @@ IpAddr HostnameToIp(const char *hostname) {
hints.ai_socktype = SOCK_STREAM;
if (getaddrinfo(hostname, nullptr, &hints, &result)) {
freeaddrinfo(result);
throw RuntimeError("Could not convert hostname (" + std::string(hostname) + ") to ip");
throw RuntimeError("Could not convert hostname (" +
std::string(hostname) + ") to ip");
}
uint32_t ip = ((sockaddr_in *)result->ai_addr)->sin_addr.s_addr;
freeaddrinfo(result);
@@ -133,7 +134,7 @@ IpAddr InterfaceNameToIp(const std::string &ifn) {
continue;
auto s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host,
NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
if ((strcmp(ifa->ifa_name, ifn.c_str()) == 0) &&
(ifa->ifa_addr->sa_family == AF_INET)) {