I use the code below to show informations about the incoming tcp packet
private static void device_OnPacketArrival(object sender, CaptureEventArgs e)
{
var time = e.Packet.Timeval.Date;
var len = e.Packet.Data.Length;
Console.WriteLine("{0}:{1}:{2},{3} Len={4}",
time.Hour, time.Minute, time.Second, time.Millisecond, len);
Console.WriteLine(e.Packet.ToString());
}
This code works fine, but now i want to get the packet in the packet, if there is one, using this code:
Packet p = PacketDotNet.Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);
var tcp = (TcpPacket)p.Extract(typeof(TcpPacket));
if (tcp.PayloadPacket != null)
Console.WriteLine(tcp.PayloadPacket.PayloadData.ToString());
and with this code the if reference always become false..
I also want to convert the html request in string format to show the requested url in the console (if the packet contains one).
Hope you can help me or give me a (complete) description link for SharpPcap, especially the Packet.Payload and converting part.