I’ve been breaking my head over this bug in my program that would rarely occur and now I finally got it down to something that is not related to my code, or at least that is what I think.
byte[] dataBuffer = new byte[512];
IPEndPoint f = new IPEndPoint(IPAddress.Parse(packet.ipAddres), SNMP_PORT);
socket.SendTo(packet.GetBytes(), f);
IPEndPoint sender = new IPEndPoint(IPAddress.Parse(packet.ipAddres), 0);
EndPoint senderRemote = (EndPoint)sender;
socket.ReceiveFrom(dataBuffer, ref senderRemote);
Wireshark packet dump and Visual Studio dump of the variable ‘dataBuffer’ do not match, screenshot
Wireshark is giving me the expected response. Visual Studio, or my code, does not.
So how is this possible? Am I using the .NET socket object incorrectly?
I’ve found the problem, the remote SNMP software on the switch.
When I send 1 GetNextRequestPDU to the switch, it should send you 1 response packet.
But sometimes this specific switch would send me 10 times the same response packet.
This results in the socket having to process 10 times the same packet before it would actually see the ‘correct’ packet. This wasn’t visible in the wireshark dump as the duplicated response happened BEFORE the visible packet in wireshark.