From 866eba936da05a856f06ba5d59ab053be74f8367 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 24 Apr 2018 00:37:53 +1000 Subject: [PATCH] Try to fix linux - compiles. but untested. --- src/network/network.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/network/network.cpp b/src/network/network.cpp index 589321d36..319460220 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -348,12 +348,16 @@ const std::vector& Network::getBroadcastAddresses() if (p->ifa_addr->sa_family == AF_INET) { struct sockaddr_in *sa = (struct sockaddr_in *) p->ifa_addr; - TransportAddress ta(sa->sin_addr, get); - char *addr = inet_ntoa(sa->sin_addr); - int ip = ((sockaddr_in*)(p->ifa_netmask))->sin_addr.s_addr; - ip = ~ip; - printf("Interface: %s\tAddress: %s\tmask: %x -> %x\n", p->ifa_name, - addr, p->ifa_netmask, htonl(ip)); + TransportAddress ta(htonl(sa->sin_addr.s_addr), 0); + uint32_t u = ((sockaddr_in*)(p->ifa_netmask))->sin_addr.s_addr; + // Convert mask to #bits: SWAT algorithm + u = u - ((u >> 1) & 0x55555555); + u = (u & 0x33333333) + ((u >> 2) & 0x33333333); + u = (((u + (u >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24; + + printf("Interface: %s\tAddress: %s\tmask: %x\n", p->ifa_name, + ta.toString().c_str(), u); + addAllBroadcastAddresses(ta, u); } }