0

I want to parse the IP packet using SharpPcap and PacketDotNet functions.. The code is:

 private static void device_OnPacketArrival(object sender, CaptureEventArgs e)
 {
 var p = PacketDotNet.Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);

            if (p != null)
            {
                var tcp = PacketDotNet.TcpPacket.GetEncapsulated(p);
                if (tcp != null)
                {

                        Console.WriteLine(tcp.SourcePort);
                        Console.WriteLine(tcp.DestinationPort);

                    }
                }

            }

where the functions refers to a handler for the event when a packet is recieved...

It parses some packets accurately but on some packets exception is raised
" TotalLength 0 < HeaderMinimumLength 20" , A first chance exception of type 'System.InvalidOperationException' occurred in PacketDotNet.dll...

This exception refers to the first line of the code
"var p = PacketDotNet.Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);" and
"e.packet.LinkLayerType" is pointed by visual studio...

plz plz help, how can i get over it....

Edited by Dani: Formatting fixed

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by skatamatic
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.