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....

Also, use code tags.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.