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
@@ -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) {