From f28c804969c91e572249211c9f0e9239c777f4f2 Mon Sep 17 00:00:00 2001 From: matt7aylor Date: Fri, 28 Nov 2025 05:14:35 +0000 Subject: [PATCH] Fixed ipv6 destination port and multicast interface issues. (#1161) --- apps/router-ipv6/main.c | 5 +++-- ports/linux/bip6.c | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/router-ipv6/main.c b/apps/router-ipv6/main.c index 0ef3b854..6d764951 100644 --- a/apps/router-ipv6/main.c +++ b/apps/router-ipv6/main.c @@ -1037,10 +1037,11 @@ static void datalink_init(void) } pEnv = getenv("BACNET_BIP6_BROADCAST"); if (pEnv) { - BACNET_IP6_ADDRESS addr; + BACNET_IP6_ADDRESS addr = { 0 }; bvlc6_address_set( - &addr, (uint16_t)strtol(pEnv, NULL, 0), 0, 0, 0, 0, 0, 0, + &addr, (uint16_t)strtol(pEnv, NULL, 16), 0, 0, 0, 0, 0, 0, BIP6_MULTICAST_GROUP_ID); + addr.port = bip6_get_port(); bip6_set_broadcast_addr(&addr); } if (!bip6_init(getenv("BACNET_BIP6_IFACE"))) { diff --git a/ports/linux/bip6.c b/ports/linux/bip6.c index c13b3b6b..e6f9faf9 100644 --- a/ports/linux/bip6.c +++ b/ports/linux/bip6.c @@ -484,12 +484,24 @@ bool bip6_init(char *ifname) bvlc6_address_set( &BIP6_Broadcast_Addr, BIP6_MULTICAST_SITE_LOCAL, 0, 0, 0, 0, 0, 0, BIP6_MULTICAST_GROUP_ID); + BIP6_Broadcast_Addr.port = BIP6_Addr.port; } /* assumes that the driver has already been initialized */ BIP6_Socket = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); if (BIP6_Socket < 0) { return false; } + + if (BIP6_Socket_Scope_Id > 0) { + unsigned int idx = BIP6_Socket_Scope_Id; + /* Explicitly set the interface for OUTGOING multicast packets */ + status = setsockopt( + BIP6_Socket, IPPROTO_IPV6, IPV6_MULTICAST_IF, &idx, sizeof(idx)); + if (status < 0) { + debug_perror("BIP6: setsockopt(IPV6_MULTICAST_IF)"); + } + } + /* Allow us to use the same socket for sending and receiving */ /* This makes sure that the src port is correct when sending */ sockopt = 1;