Burak Dincer
Burak Dincer

Reputation: 65

Tcp raw packets

I use PcapDotnet wrapper for sniff packets but it show just ip raw packets for example at clientside i send that packet

 client_.Send(ASCIIEncoding.ASCII.GetBytes("test"));

and at serverside i want to capture "test" but packet.Buffer show different 66 bytes.Can i get just "test" packets ?

  private static void PacketHandler(Packet packet)
    {
        IpV4Datagram ip = packet.Ethernet.IpV4;
        TcpDatagram tcp = ip.Tcp;

        if (tcp.DestinationPort == 28001 || tcp.SourcePort == 28001)
        {
            File.AppendAllText("return.txt", ASCIIEncoding.ASCII.GetString(packet.Buffer));
            Console.WriteLine(ip.Source + ":" + tcp.SourcePort + " -> " + ip.Destination + ":" + tcp.DestinationPort);
        }
    }

Upvotes: 0

Views: 656

Answers (1)

divinci
divinci

Reputation: 23119

File.AppendAllText("return.txt", ASCIIEncoding.ASCII.GetString(packet.Buffer));

is printing ALL the binary, including the IPv4 header and the TCP header.

try just:

File.AppendAllText("return.txt", ASCIIEncoding.ASCII.GetString(tcp.Payload??));

Upvotes: 1

Related Questions