bip: decouple broadcast destination port from bind port (#1311)
Co-authored-by: Leunar Kalludra <Leunar.Kalludra@de.bosch.com>
This commit is contained in:
+28
-2
@@ -25,6 +25,8 @@ static int BIP_Broadcast_Socket = -1;
|
||||
/* port to use - stored here in network byte order */
|
||||
/* Initialize to 0 - this will force initialization in demo apps */
|
||||
static uint16_t BIP_Port;
|
||||
/* broadcast destination port to use */
|
||||
static uint16_t BIP_Broadcast_Port;
|
||||
/* IP address - stored here in network byte order */
|
||||
static struct in_addr BIP_Address;
|
||||
/* IP broadcast address - stored here in network byte order */
|
||||
@@ -103,6 +105,15 @@ void bip_set_port(uint16_t port)
|
||||
BIP_Port = htons(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the BACnet IPv4 UDP broadcast destination port number
|
||||
* @param port - IPv4 UDP port number - in host byte order
|
||||
*/
|
||||
void bip_set_broadcast_port(uint16_t port)
|
||||
{
|
||||
BIP_Broadcast_Port = htons(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the BACnet IPv4 UDP port number
|
||||
* @return IPv4 UDP port number - in host byte order
|
||||
@@ -112,6 +123,19 @@ uint16_t bip_get_port(void)
|
||||
return ntohs(BIP_Port);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the BACnet IPv4 UDP broadcast destination port number
|
||||
* @return IPv4 UDP port number - in host byte order
|
||||
*/
|
||||
uint16_t bip_get_broadcast_port(void)
|
||||
{
|
||||
if (BIP_Broadcast_Port) {
|
||||
return ntohs(BIP_Broadcast_Port);
|
||||
}
|
||||
|
||||
return ntohs(BIP_Port);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the IPv4 address for my interface. Used for sending src address.
|
||||
* @param addr - BACnet datalink address
|
||||
@@ -143,11 +167,12 @@ void bip_get_my_address(BACNET_ADDRESS *addr)
|
||||
void bip_get_broadcast_address(BACNET_ADDRESS *dest)
|
||||
{
|
||||
int i = 0; /* counter */
|
||||
uint16_t port = htons(bip_get_broadcast_port());
|
||||
|
||||
if (dest) {
|
||||
dest->mac_len = 6;
|
||||
memcpy(&dest->mac[0], &BIP_Broadcast_Addr.s_addr, 4);
|
||||
memcpy(&dest->mac[4], &BIP_Port, 2);
|
||||
memcpy(&dest->mac[4], &port, 2);
|
||||
dest->net = BACNET_BROADCAST_NETWORK;
|
||||
dest->len = 0; /* no SLEN */
|
||||
for (i = 0; i < MAX_MAC_LEN; i++) {
|
||||
@@ -207,7 +232,7 @@ bool bip_get_broadcast_addr(BACNET_IP_ADDRESS *addr)
|
||||
{
|
||||
if (addr) {
|
||||
memcpy(&addr->address[0], &BIP_Broadcast_Addr.s_addr, 4);
|
||||
addr->port = ntohs(BIP_Port);
|
||||
addr->port = bip_get_broadcast_port();
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -814,6 +839,7 @@ void bip_cleanup(void)
|
||||
/* these were set non-zero during interface configuration */
|
||||
BIP_Address.s_addr = 0;
|
||||
BIP_Broadcast_Addr.s_addr = 0;
|
||||
BIP_Broadcast_Port = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user