Feature/bacnet ipv6 bind interface for link local comunication (#359)

This commit is contained in:
Patrick Grimm
2022-11-20 21:29:11 +01:00
committed by GitHub
parent 78fd0cf9cb
commit 8e6b3fafab
3 changed files with 15 additions and 6 deletions
+5 -2
View File
@@ -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,