From b40a6a51f368a06c30bfdaa9ccf16ff1e03b9a56 Mon Sep 17 00:00:00 2001 From: Andrea Bondavalli Date: Sun, 14 Jun 2020 23:13:48 +0200 Subject: [PATCH] Node ID generation is based on the IP address of the selected interface. Removed call to gethostid() function that is buggy and can create troubles. --- daemon/utils.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/daemon/utils.cpp b/daemon/utils.cpp index a89c957..5278d2e 100755 --- a/daemon/utils.cpp +++ b/daemon/utils.cpp @@ -76,17 +76,9 @@ parse_url(const std::string& _url) { std::string get_node_id(uint32_t ip_addr) { std::stringstream ss; - if (gethostid() == 0x7f0101) { - /* hostid is using lo interface ip - we create an host ID based on the current IP */ - ss << "AES67 daemon " - << boost::format("%02x%02x%02x%02x") - % ((ip_addr >> 8) & 0xff) - % ((ip_addr >> 24) & 0xff) - % (ip_addr & 0xff) - % ((ip_addr >> 16) & 0xff); - } else { - ss << "AES67 daemon " << std::hex << (uint32_t)gethostid(); - } + ip_addr = htonl(ip_addr); + /* we create an host ID based on the current IP */ + ss << "AES67 daemon " << boost::format("%08x") % + ((ip_addr << 16) | (ip_addr >> 16)); return ss.str(); }