From 59a65ce317aee13c4c7b0883b436779e15de26be Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Mon, 2 Jul 2018 15:56:16 -0700 Subject: [PATCH] discoverInterfaces() fixup bcast address on win32 Apparently SIO_GET_INTERFACE_LIST sometimes gives the global broadcast (255.255.255.255) for one of the interfaces. In this case silently compute the iface bcast address. --- src/utils/inetAddressUtil.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/utils/inetAddressUtil.cpp b/src/utils/inetAddressUtil.cpp index 3f7a43e..062a34f 100644 --- a/src/utils/inetAddressUtil.cpp +++ b/src/utils/inetAddressUtil.cpp @@ -199,7 +199,7 @@ ifaceNode::ifaceNode() } static -void checkNode(const ifaceNode& node) +void checkNode(ifaceNode& node) { if(node.validBcast) { /* Cross-check between addr, mask, and bcast to detect incorrect broadcast @@ -210,9 +210,16 @@ void checkNode(const ifaceNode& node) bcast= ntohl(node.bcast.ia.sin_addr.s_addr), bcast_expect = (addr & mask) | ~mask; + if(bcast == ntohl(INADDR_BROADCAST)) { + // translate global broadcast to iface broadcast. + // Windows (at least) will give us this sometimes. + bcast = bcast_expect; + node.bcast.ia.sin_addr.s_addr = htonl(bcast); + } + if(bcast != bcast_expect) { - errlogPrintf("Detected inconsistent broadcast address on interface %08x/%08x. expect %08x found ~%08x.", - addr, mask, bcast_expect, bcast); + errlogPrintf("Warning: Inconsistent broadcast address on interface %08x/%08x. expect %08x found %08x.\n", + (unsigned)addr, (unsigned)mask, (unsigned)bcast_expect, (unsigned)bcast); } } }