Skip to content

Commit

Permalink
Enabled multicast based discovery in IPv6.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Oct 16, 2024
1 parent 705dcaf commit 862b1ac
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions SharpSnmpLib/Messaging/Discoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public sealed partial class Discoverer
/// <param name="broadcastAddress">The broadcast address.</param>
/// <param name="community">The community.</param>
/// <param name="interval">The discovering time interval, in milliseconds.</param>
/// <remarks><paramref name="broadcastAddress"/> must be an IPv4 address. IPv6 is not yet supported here.</remarks>
/// <remarks><paramref name="broadcastAddress"/> must be configured to a valid multicast address when IPv6 is used. For example, "[ff02::1]:161"</remarks>
public void Discover(VersionCode version, IPEndPoint broadcastAddress, OctetString community, int interval)
{
if (broadcastAddress == null)
Expand All @@ -72,11 +72,6 @@ public void Discover(VersionCode version, IPEndPoint broadcastAddress, OctetStri
}

var addressFamily = broadcastAddress.AddressFamily;
if (addressFamily == AddressFamily.InterNetworkV6)
{
throw new ArgumentException("IP v6 is not yet supported.", nameof(broadcastAddress));
}

byte[] bytes;
_requestId = Messenger.NextRequestId;
if (version == VersionCode.V3)
Expand All @@ -91,9 +86,16 @@ public void Discover(VersionCode version, IPEndPoint broadcastAddress, OctetStri
}

using var udp = new UdpClient(addressFamily);
if (addressFamily == AddressFamily.InterNetworkV6)
{
udp.JoinMulticastGroup((IPAddress?)broadcastAddress.Address);

Check warning on line 91 in SharpSnmpLib/Messaging/Discoverer.cs

View workflow job for this annotation

GitHub Actions / windows

Possible null reference argument for parameter 'multicastAddr' in 'void UdpClient.JoinMulticastGroup(IPAddress multicastAddr)'.
}
else if (addressFamily == AddressFamily.InterNetwork)
{
#if (!CF)
udp.EnableBroadcast = true;
udp.EnableBroadcast = true;
#endif
}
#if NET471
udp.Send(bytes, bytes.Length, broadcastAddress);
#else
Expand Down

0 comments on commit 862b1ac

Please sign in to comment.