I want to received raw TCP packet and then send it back with same workload.
It should look something like this:
void OnPacketReceived(TcpPacket p)
{
byte [] body = p.GetBody();
}
NOTE : I need the TCP packet and not the Ethernet frame.
Creating a packet In scapy, packets are constructed by defining packet headers for each protocol at different layers of TCP/IP and then stacking these layers in order. To create a DNS query, you need to build Ether(sometimes optional), IP,UDP headers and stack them using / operator.
To create a socket of type SOCK_RAW, call the socket or WSASocket function with the af parameter (address family) set to AF_INET or AF_INET6, the type parameter set to SOCK_RAW, and the protocol parameter set to the protocol number required.
Raw packet is used when you dont have any, the first bytes captured are directly the IPv6 or IPv4 header. Raw IP; the packet begins with an IPv4 or IPv6 header, with the "version" field of the header indicating whether it's an IPv4 or IPv6 header.
Raw sockets operate at the network OSI level, which means that transport-level headers such as TCP or UDP headers will not be automatically decoded. If you are implementing a a transport-level protocol, you'll have to write code to decode and encode the transport-level headers in your application.
If you implement the socket as a raw socket, you have access to the whole packet (and in fact must handle everything about the packet yourself).
Use SocketType.Raw and ProtocolType.Raw when creating the socket.
Just be aware that you're going to have to handle the details of TCP if you implement your socket this way.
For reference, here is the MSDN documentation about the Socket class: http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With