From 6cb014ee64c7b94a22ad1a768821be2f4b902ece Mon Sep 17 00:00:00 2001 From: skarg Date: Tue, 24 Feb 2015 21:55:31 +0000 Subject: [PATCH] Changed the Linux BACnet/IP init to use NetMask. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function was modified to calculate the broadcast address from IP and netmask instead of using SIOCGIFBRDADDR. In some cases it is possible that the ioctl is successful, but the returned address is 0 (e.g. search for Bcast: 0.0.0.0). For some reason in Linux the local loopback device answers from 0.0.0.0 address. So messages broadcast to that address are received from 127.0.0.1 which can possibly create a broadcast loop. This has nothing to do with NAT, but makes the stack more robust. Thank you, Sami Pietikäinen, for the contribution! --- bacnet-stack/ports/linux/bip-init.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bacnet-stack/ports/linux/bip-init.c b/bacnet-stack/ports/linux/bip-init.c index 508d6703..3048ccba 100644 --- a/bacnet-stack/ports/linux/bip-init.c +++ b/bacnet-stack/ports/linux/bip-init.c @@ -107,6 +107,7 @@ void bip_set_interface( { struct in_addr local_address; struct in_addr broadcast_address; + struct in_addr netmask; int rv = 0; /* setup local address */ @@ -120,10 +121,15 @@ void bip_set_interface( fprintf(stderr, "IP Address: %s\n", inet_ntoa(local_address)); } /* setup local broadcast address */ - rv = get_local_address_ioctl(ifname, &broadcast_address, SIOCGIFBRDADDR); + rv = get_local_address_ioctl(ifname, &netmask, SIOCGIFNETMASK); + if (rv < 0) { broadcast_address.s_addr = ~0; } + else { + broadcast_address = local_address; + broadcast_address.s_addr |= (~netmask.s_addr); + } bip_set_broadcast_addr(broadcast_address.s_addr); if (BIP_Debug) { fprintf(stderr, "IP Broadcast Address: %s\n",