Changed the Linux BACnet/IP init to use NetMask.

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!
This commit is contained in:
skarg
2015-02-24 21:55:31 +00:00
parent 98207470f4
commit 6cb014ee64
+7 -1
View File
@@ -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",