diff --git a/SharpSnmpLib/Messaging/ListenerBinding.cs b/SharpSnmpLib/Messaging/ListenerBinding.cs index 62196098..389566b6 100644 --- a/SharpSnmpLib/Messaging/ListenerBinding.cs +++ b/SharpSnmpLib/Messaging/ListenerBinding.cs @@ -182,7 +182,7 @@ public void Start() return; } - _socket = new Socket(addressFamily, SocketType.Dgram, ProtocolType.Udp); + _socket = new Socket(addressFamily, SocketType.Dgram, ProtocolType.Udp) { ExclusiveAddressUse = true }; try { @@ -244,10 +244,10 @@ private void AsyncBeginReceive() while (true) { // If no more active, then stop. - if (Interlocked.Read(ref _active) == 0) + if (Interlocked.Read(ref _active) == Inactive) + { return; - - //Console.WriteLine("Waiting"); + } byte[] buffer = new byte[_bufferSize]; EndPoint remote = new IPEndPoint(IPAddress.Any, 0); @@ -271,7 +271,10 @@ private void AsyncBeginReceive() } } - iar.AsyncWaitHandle.WaitOne(); + if (iar != null) + { + iar.AsyncWaitHandle.WaitOne(); + } } } @@ -279,8 +282,10 @@ private void AsyncEndReceive(IAsyncResult iar) { // If no more active, then stop. This discards the received packet, if any (indeed, we may be there either // because we've received a packet, or because the socket has been closed). - if (Interlocked.Read(ref _active) == 0) + if (Interlocked.Read(ref _active) == Inactive) + { return; + } //// We start another receive operation. //AsyncBeginReceive(); @@ -289,7 +294,7 @@ private void AsyncEndReceive(IAsyncResult iar) try { - EndPoint remote = new IPEndPoint(IPAddress.Any, 0); + EndPoint remote = _socket.AddressFamily == AddressFamily.InterNetwork ? new IPEndPoint(IPAddress.Any, 0) : new IPEndPoint(IPAddress.IPv6Any, 0); int count = _socket.EndReceiveFrom(iar, ref remote); HandleMessage(new MessageParams(buffer, count, remote)); } diff --git a/SharpSnmpLib/Pipeline/SecureSnmpContext.cs b/SharpSnmpLib/Pipeline/SecureSnmpContext.cs index 20034de4..ee07253e 100644 --- a/SharpSnmpLib/Pipeline/SecureSnmpContext.cs +++ b/SharpSnmpLib/Pipeline/SecureSnmpContext.cs @@ -142,6 +142,11 @@ public override void GenerateTooBig() Request.Pdu.Variables)), privacy, true); + if (TooBig) + { + Response = null; + // TODO: snmpSilentDrops++; + } } /// diff --git a/SharpSnmpLib/SharpSnmpLib.Controls.csproj b/SharpSnmpLib/SharpSnmpLib.Controls.csproj index 689e02ba..47231ec5 100644 --- a/SharpSnmpLib/SharpSnmpLib.Controls.csproj +++ b/SharpSnmpLib/SharpSnmpLib.Controls.csproj @@ -34,7 +34,7 @@ full false bin\Debug\ - DEBUG;TRACE + TRACE;DEBUG prompt 4