diff --git a/ports/bsd/bip6.c b/ports/bsd/bip6.c index 6babb427..bfc19c03 100644 --- a/ports/bsd/bip6.c +++ b/ports/bsd/bip6.c @@ -100,6 +100,7 @@ void bip6_debug_enable(void) /* unix socket */ static int BIP6_Socket = -1; +static int BIP6_Socket_Scope_Id = 0; /* local address - filled by init functions */ static BACNET_IP6_ADDRESS BIP6_Addr; static BACNET_IP6_ADDRESS BIP6_Broadcast_Addr; @@ -140,6 +141,7 @@ void bip6_set_interface(char *ifname) ntohs(sin->sin6_addr.s6_addr16[7])); debug_print_ipv6(ifname, (&sin->sin6_addr)); found = true; + BIP6_Socket_Scope_Id = if_nametoindex(ifname); break; } ifa_tmp = ifa_tmp->ifa_next; @@ -274,6 +276,7 @@ int bip6_send_mpdu(BACNET_IP6_ADDRESS *dest, uint8_t *mtu, uint16_t mtu_len) bvlc_dest.sin6_addr.s6_addr16[6] = htons(addr16[6]); bvlc_dest.sin6_addr.s6_addr16[7] = htons(addr16[7]); bvlc_dest.sin6_port = htons(dest->port); + bvlc_dest.sin6_scope_id = BIP6_Socket_Scope_Id; debug_print_ipv6("Sending MPDU->", &bvlc_dest.sin6_addr); /* Send the packet */ return sendto(BIP6_Socket, (char *)mtu, mtu_len, 0, @@ -464,8 +467,8 @@ bool bip6_init(char *ifname) IP6_ADDRESS_MAX); memcpy(&join_request.ipv6mr_multiaddr, &broadcast_address, sizeof(struct in6_addr)); - /* Let system choose the interface */ - join_request.ipv6mr_interface = 0; + /* Let system not choose the interface */ + join_request.ipv6mr_interface = BIP6_Socket_Scope_Id; status = setsockopt(BIP6_Socket, IPPROTO_IPV6, IPV6_JOIN_GROUP, &join_request, sizeof(join_request)); if (status < 0) { diff --git a/ports/linux/bip6.c b/ports/linux/bip6.c index e457ec39..876cbccf 100644 --- a/ports/linux/bip6.c +++ b/ports/linux/bip6.c @@ -90,6 +90,7 @@ void bip6_debug_enable(void) /* unix socket */ static int BIP6_Socket = -1; +static int BIP6_Socket_Scope_Id = 0; /* local address - filled by init functions */ static BACNET_IP6_ADDRESS BIP6_Addr; static BACNET_IP6_ADDRESS BIP6_Broadcast_Addr; @@ -130,6 +131,7 @@ void bip6_set_interface(char *ifname) ntohs(sin->sin6_addr.s6_addr16[7])); debug_print_ipv6(ifname, (&sin->sin6_addr)); found = true; + BIP6_Socket_Scope_Id = if_nametoindex(ifname); break; } ifa_tmp = ifa_tmp->ifa_next; @@ -264,6 +266,7 @@ int bip6_send_mpdu(BACNET_IP6_ADDRESS *dest, uint8_t *mtu, uint16_t mtu_len) bvlc_dest.sin6_addr.s6_addr16[6] = htons(addr16[6]); bvlc_dest.sin6_addr.s6_addr16[7] = htons(addr16[7]); bvlc_dest.sin6_port = htons(dest->port); + bvlc_dest.sin6_scope_id = BIP6_Socket_Scope_Id; debug_print_ipv6("Sending MPDU->", &bvlc_dest.sin6_addr); /* Send the packet */ return sendto(BIP6_Socket, (char *)mtu, mtu_len, 0, @@ -454,8 +457,8 @@ bool bip6_init(char *ifname) IP6_ADDRESS_MAX); memcpy(&join_request.ipv6mr_multiaddr, &broadcast_address, sizeof(struct in6_addr)); - /* Let system choose the interface */ - join_request.ipv6mr_interface = 0; + /* Let system not choose the interface */ + join_request.ipv6mr_interface = BIP6_Socket_Scope_Id; status = setsockopt(BIP6_Socket, IPPROTO_IPV6, IPV6_JOIN_GROUP, &join_request, sizeof(join_request)); if (status < 0) { diff --git a/ports/win32/bip6.c b/ports/win32/bip6.c index c3a297b5..fcd9ce3d 100644 --- a/ports/win32/bip6.c +++ b/ports/win32/bip6.c @@ -46,6 +46,7 @@ /* Win32 Socket */ static SOCKET BIP6_Socket = INVALID_SOCKET; +static int BIP6_Socket_Scope_Id = 0; /* local address - filled by init functions */ static BACNET_IP6_ADDRESS BIP6_Addr; static BACNET_IP6_ADDRESS BIP6_Broadcast_Addr; @@ -207,8 +208,9 @@ void bip6_set_interface(char *ifname) IP6_ADDRESS_MAX); memcpy(&join_request.ipv6mr_multiaddr, &broadcast_address, sizeof(struct in6_addr)); - /* Let system choose the interface */ - join_request.ipv6mr_interface = 0; + /* Let system not choose the interface */ + BIP6_Socket_Scope_Id = if_nametoindex(ifname); + join_request.ipv6mr_interface = BIP6_Socket_Scope_Id; RetVal = setsockopt(BIP6_Socket, IPPROTO_IPV6, IPV6_JOIN_GROUP, (char *)&join_request, sizeof(join_request)); if (RetVal < 0) { @@ -389,6 +391,7 @@ int bip6_send_mpdu(BACNET_IP6_ADDRESS *dest, uint8_t *mtu, uint16_t mtu_len) bvlc_dest.sin6_addr.s6_addr16[6] = htons(addr16[6]); bvlc_dest.sin6_addr.s6_addr16[7] = htons(addr16[7]); bvlc_dest.sin6_port = htons(dest->port); + bvlc_dest.sin6_scope_id = BIP6_Socket_Scope_Id; debug_print_ipv6("Sending MPDU->", &bvlc_dest.sin6_addr); /* Send the packet */ return sendto(BIP6_Socket, (char *)mtu, mtu_len, 0,