How do you get the raw TCP packet in C #?

I want to receive a raw TCP packet, and then send it with the same workload.

It should look something like this:

void OnPacketReceived(TcpPacket p) { byte [] body = p.GetBody(); } 

NOTE. I need a TCP packet, not an Ethernet frame.

+8
c # networking tcp
source share
3 answers

If you implement a socket as a raw socket, you have access to the entire packet (and in fact, it must handle everything about the packet itself).

Use SocketType.Raw and ProtocolType.Raw when creating a socket.

Just keep in mind that you will have to handle TCP details if you implement your socket this way.

For reference, here is the MSDN documentation for the Socket class: http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx

+6
source share

You can use the pcapDotNet library.

https://pcapdotnet.codeplex.com/

+2
source share

you need to use a packet sniffer where you can put filters of your choice and based on this you can also answer.

. The wrapper around WinPcap may be useful to you.

0
source share

All Articles