diff --git a/bacnet-stack/bip.c b/bacnet-stack/bip.c index c7c4ae0d..f1aea3dc 100644 --- a/bacnet-stack/bip.c +++ b/bacnet-stack/bip.c @@ -125,21 +125,23 @@ int bip_send_pdu(BACNET_ADDRESS * dest, /* destination address */ mtu[0] = BVLL_TYPE_BACNET_IP; bip_dest.sin_family = AF_INET; - if (dest->mac_len == 6) { + if (dest->net == BACNET_BROADCAST_NETWORK) { + /* broadcast */ + bip_dest.sin_addr.s_addr = htonl(BIP_Broadcast_Address.s_addr); + bip_dest.sin_port = htons(BIP_Port); + memset(&(bip_dest.sin_zero), '\0', 8); + mtu[1] = BVLC_ORIGINAL_BROADCAST_NPDU; + } else if (dest->mac_len == 6) { + /* valid unicast */ (void) decode_unsigned32(&dest->mac[0], &(bip_dest.sin_addr.s_addr)); (void) decode_unsigned16(&dest->mac[4], &(bip_dest.sin_port)); memset(&(bip_dest.sin_zero), '\0', 8); mtu[1] = BVLC_ORIGINAL_UNICAST_NPDU; - } - /* broadcast */ - else if (dest->mac_len == 0) { - bip_dest.sin_addr.s_addr = htonl(BIP_Broadcast_Address.s_addr); - bip_dest.sin_port = htons(BIP_Port); - memset(&(bip_dest.sin_zero), '\0', 8); - mtu[1] = BVLC_ORIGINAL_BROADCAST_NPDU; - } else + } else { + /* invalid address */ return -1; + } mtu_len = 2; mtu_len += diff --git a/bacnet-stack/ports/linux/arcnet.c b/bacnet-stack/ports/linux/arcnet.c index efe6410c..ca210394 100644 --- a/bacnet-stack/ports/linux/arcnet.c +++ b/bacnet-stack/ports/linux/arcnet.c @@ -350,7 +350,7 @@ void arcnet_get_my_address(BACNET_ADDRESS * my_address) my_address->mac_len = 1; my_address->mac[0] = ARCNET_MAC_Address; - my_address->net = 0; /* local only, no routing */ + my_address->net = 0; /* DNET=0 is local only, no routing */ my_address->len = 0; for (i = 0; i < MAX_MAC_LEN; i++) { my_address->adr[i] = 0; @@ -367,7 +367,7 @@ void arcnet_get_broadcast_address(BACNET_ADDRESS * dest) dest->mac[0] = ARCNET_BROADCAST; dest->mac_len = 1; dest->net = BACNET_BROADCAST_NETWORK; - dest->len = 0; /* len=0 denotes broadcast address */ + dest->len = 0; /* always zero when DNET is broadcast */ for (i = 0; i < MAX_MAC_LEN; i++) { dest->adr[i] = 0; } diff --git a/bacnet-stack/ports/linux/ethernet.c b/bacnet-stack/ports/linux/ethernet.c index c9fad44d..d7373d75 100644 --- a/bacnet-stack/ports/linux/ethernet.c +++ b/bacnet-stack/ports/linux/ethernet.c @@ -349,7 +349,7 @@ void ethernet_get_my_address(BACNET_ADDRESS * my_address) my_address->mac[i] = Ethernet_MAC_Address[i]; my_address->mac_len++; } - my_address->net = 0; /* local only, no routing */ + my_address->net = 0; /* DNET=0 is local only, no routing */ my_address->len = 0; for (i = 0; i < MAX_MAC_LEN; i++) { my_address->adr[i] = 0; @@ -368,7 +368,7 @@ void ethernet_get_broadcast_address(BACNET_ADDRESS * dest) } dest->mac_len = 6; dest->net = BACNET_BROADCAST_NETWORK; - dest->len = 0; /* denotes broadcast address */ + dest->len = 0; /* always zero when DNET is broadcast */ for (i = 0; i < MAX_MAC_LEN; i++) { dest->adr[i] = 0; } diff --git a/bacnet-stack/ports/pic18f6720/dlmstp.c b/bacnet-stack/ports/pic18f6720/dlmstp.c index 60c09807..0c045024 100644 --- a/bacnet-stack/ports/pic18f6720/dlmstp.c +++ b/bacnet-stack/ports/pic18f6720/dlmstp.c @@ -315,7 +315,7 @@ void dlmstp_get_broadcast_address(BACNET_ADDRESS * dest) dest->mac_len = 1; dest->mac[0] = MSTP_BROADCAST_ADDRESS; dest->net = BACNET_BROADCAST_NETWORK; - dest->len = 0; /* len=0 denotes broadcast address */ + dest->len = 0; /* always zero when DNET is broadcast */ for (i = 0; i < MAX_MAC_LEN; i++) { dest->adr[i] = 0; }