#ifndef FAIRMQTOOLS_H_ #define FAIRMQTOOLS_H_ #ifndef _GNU_SOURCE #define _GNU_SOURCE /* To get defns of NI_MAXSERV and NI_MAXHOST */ #endif #include #include #include #include #include #include #include #include using namespace std; namespace FairMQ { namespace tools { int getHostIPs(map& addressMap) { struct ifaddrs *ifaddr, *ifa; int s; char host[NI_MAXHOST]; if (getifaddrs(&ifaddr) == -1) { perror("getifaddrs"); return -1; } for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { if (ifa->ifa_addr == NULL) { continue; } if (ifa->ifa_addr->sa_family == AF_INET) { s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); if (s != 0) { cout << "getnameinfo() failed: " << gai_strerror(s) << endl; return -1; } addressMap.insert(pair(ifa->ifa_name, host)); } } freeifaddrs(ifaddr); return 0; } } // namespace tools } // namespace FairMQ #endif