Skip to content
Snippets Groups Projects
Commit f8cf24a6 authored by George Sedov's avatar George Sedov
Browse files

change the way the IB IP is found

parent e5d42792
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,10 @@
#include <iostream>
#include <unistd.h>
#include <limits.h>
#include <netdb.h>
#include <string.h>
#include <arpa/inet.h>
namespace asapo {
......@@ -67,19 +70,24 @@ Error ReceiverConfigManager::ReadConfigFromFile(std::string file_name) {
}
// try to discover an IB address. It should be resolved by <hostname>-ib.desy.de, if exists
char hostname[250];
gethostname(hostname, 250);
std::string hostnamestr {hostname};
auto pos = hostnamestr.find('.');
if (pos != std::string::npos) {
hostnamestr = hostnamestr.substr(0, pos) + "-ib" + hostnamestr.substr(pos);
char hostname[HOST_NAME_MAX + 1];
char hostname_ib[HOST_NAME_MAX + 4];
gethostname(hostname, HOST_NAME_MAX);
auto pos = strchr(hostname, '.');
if (pos != NULL) {
memmove(pos+3, pos, strlen(pos));
sprintf(hostname_ib, "%.*s-ib%s", (int) (pos - hostname), hostname, pos + 3);
} else {
hostnamestr += "-ib";
sprintf(hostname_ib, "%s-ib", hostname);
}
auto record = gethostbyname(hostnamestr.c_str());
if (record != nullptr && record->h_addr_list != nullptr) {
pos = config.dataserver.advertise_uri.find(':');
config.dataserver.advertise_ib_uri = record->h_addr_list[0] + config.dataserver.advertise_uri.substr(pos);
struct addrinfo *result;
if (getaddrinfo(hostname_ib, NULL, NULL, &result) == 0) {
inet_ntop(AF_INET, &((struct sockaddr_in *)result->ai_addr)->sin_addr, hostname_ib, INET_ADDRSTRLEN);
auto strpos = config.dataserver.advertise_uri.find(':');
config.dataserver.advertise_ib_uri = hostname_ib + config.dataserver.advertise_uri.substr(strpos);
freeaddrinfo(result);
}
config.dataserver.tag = config.tag + "_ds";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment