fix BACnet/IP on OS to bind broadcast to specific port (#489)

* Fixes #346 by binding the broadcast socket to the port specific broadcast address rather than INADDR_ANY or INADDR_BROADCAST. Added additional compile and environment options for those who might need them. 

* Changed the define USE_CLASSADDR to BACNET_IP_BROADCAST_USE_CLASSADDR to help manage namespaces.

* Added BACNET_IP_BROADCAST_BIND_ADDR environment variable to override the default broadcast binding address.

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2023-09-10 10:24:18 -05:00
committed by GitHub
parent 0001f85f29
commit 55b8b3d93c
18 changed files with 231 additions and 58 deletions
+4
View File
@@ -122,6 +122,10 @@ extern "C" {
BACNET_STACK_EXPORT
int bip_get_broadcast_socket(void);
BACNET_STACK_EXPORT
int bip_set_broadcast_binding(
const char *ip4_broadcast);
#ifdef __cplusplus
}
#endif /* __cplusplus */
+5
View File
@@ -524,6 +524,7 @@ void dlenv_maintenance_timer(uint16_t elapsed_seconds)
* - BACNET_BDT_MASK_1 - dotted IPv4 mask of the BBMD table
* entry 1..128 (optional)
* - BACNET_IP_NAT_ADDR - dotted IPv4 address of the public facing router
* - BACNET_IP_BROADCAST_BIND_ADDR - dotted IPv4 address to bind broadcasts
* - BACDL_MSTP: (BACnet MS/TP)
* - BACNET_MAX_INFO_FRAMES
* - BACNET_MAX_MASTER
@@ -592,6 +593,10 @@ void dlenv_init(void)
bip_set_port(0xBAC0);
}
}
pEnv = getenv("BACNET_IP_BROADCAST_BIND_ADDR");
if (pEnv) {
bip_set_broadcast_binding(pEnv);
}
pEnv = getenv("BACNET_IP_NAT_ADDR");
if (pEnv) {
if (bip_get_addr_by_name(pEnv, &addr)) {