Skip to content

Commit

Permalink
Expansion of PR 26: Fix multicast responses not being sent out on all…
Browse files Browse the repository at this point in the history
… interfaces

Co-authored-by: Laurie Kirkcaldy <lauriekirkcaldy@gmail.com>
  • Loading branch information
jdomnitz and Electronics committed Jul 2, 2024
1 parent 1352a08 commit 1b817e4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/MulticastClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,19 @@ public MulticastClient(bool useIPv4, bool useIpv6, IEnumerable<NetworkInterface>
switch (address.AddressFamily)
{
case AddressFamily.InterNetwork:
receiver4.Client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(MulticastAddressIp4, address));
MulticastOption mcastOption4 = new MulticastOption(MulticastAddressIp4, address);
receiver4.Client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, mcastOption4);
sender.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
sender.Client.Bind(localEndpoint);
sender.Client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(MulticastAddressIp4));
sender.Client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, mcastOption4);
sender.Client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastLoopback, true);
break;
case AddressFamily.InterNetworkV6:
receiver6.Client.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.AddMembership, new IPv6MulticastOption(MulticastAddressIp6, address.ScopeId));
IPv6MulticastOption mcastOption6 = new IPv6MulticastOption(MulticastAddressIp6, address.ScopeId);
receiver6.Client.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.AddMembership, mcastOption6);
sender.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
sender.Client.Bind(localEndpoint);
sender.Client.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.AddMembership, new IPv6MulticastOption(MulticastAddressIp6));
sender.Client.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.AddMembership, mcastOption6);
sender.Client.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.MulticastLoopback, true);
break;
default:
Expand Down

0 comments on commit 1b817e4

Please sign in to comment.