0

I cant create these objects in pcap.net

IpV4Datagram ip = packet.Ethernet.IpV4;
        TcpDatagram tcp = ip.Tcp;
        HttpDatagram http = tcp.Http;
     //   HttpResponseDatagram resdat=http.;  How can i create them?
     //   HttpResponseLayer resp;
if (tcp.Http.Body != null && http.IsResponse)
            body = resp.Body.ToString();

I'm trying to get HTTP Response Body from a tcp packet. If there is another way to do it can someone help?

  • Is there a reason that you are working at the _packet_ lever? Most sites run a packet size in the area of 1460 bytes, and a typical page has content many times that. – Mad Myche May 16 '17 at 21:50
  • I 'm making a tcp listener i listen all the packets coming. It's not a problem with packet count. – Gökberk Açıkgöz May 17 '17 at 22:49

1 Answers1

0

In the Pcap.Net User Guide, there's a section about sending packets. In that section, there is an example on how to create HttpRequestLayer, and creating HttpResponseLayer is very similar.

 HttpRequestLayer httpLayer =
     new HttpRequestLayer
     {
         Version = HttpVersion.Version11,
         Header = new HttpHeader(new HttpContentLengthField(11)),
         Body = new Datagram(Encoding.ASCII.GetBytes("hello world")),
         Method = new HttpRequestMethod(HttpRequestKnownMethod.Get),
         Uri = @"http://pcapdot.net/",
     };

HttpResponseDatagram is creating by parsing an HTTP packet. For example, by doing

packet.Ethernet.IpV4.Tcp.Http

There's no simple way of creating a Datagram without parsing a packet.

brickner
  • 6,595
  • 3
  • 41
  • 54