I want to send a TCP packet (with a custom header) in C#. The building of such packets is no problem, and I have the data in a byte array. But how can I send this packet over a socket?
I tried something like this:
using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP))
{
TcpPacket tcpPacket = new TcpPacket();
// fill tcpPacket with data
sock.Bind(new IPEndPoint(MYADDRESS, MYPORT));
byte[] data = tcpPacket.GetBytes();
sock.SendTo(data, new IPEndPoint(DESTADDRESS, DESTPORT));
}
This runs without any exception but sniffing the network shows that nothing is send. What is the solution?
I use Windows 7 Professional, and I don't want the system to create the full TCP connection all alone.
PS: I don't want to use some other library.
PS: Building IP packets is not a problem, either.