Hi
I am using sockets to make a simulation of gateway. I just wanted to ask how do i drop a packet so that the system itself sends it again. Or do i have to make some of my own functions for the simulation purposes?
Hi
I am using sockets to make a simulation of gateway. I just wanted to ask how do i drop a packet so that the system itself sends it again. Or do i have to make some of my own functions for the simulation purposes?
You can't with normal sockets. Sockets are built on top of the transport layer, and therefore you can't drop a TCP packet without sending the ACK back.
For simulation purposes, you can rewrite the TCP using UDP packets. Then you have the ability to drop packets and what not.
Another option would be to write something on the driver level which could filter indivudual packets. Then your simulation would be true to the actual TCP implementation between the machines you are working on. This method is OS dependent, and perhaps even hardware dependent (NIC dependent). On windows you could write an intermediate driver which would be a bit easier than writing an actual NIC driver. On linux, you could modify the source of a pre-existing driver to suit your needs.
Can you explain a bit about what do u mean when u say implement TCP using UDP. Even then there will be no difference in my opinion.
Well TCP implements several things like sequence numbers, acknowledgement packets, a checksum, and a sliding window which you would have to implement on top of UDP.
Here is how it would look:
Sender sends X number of packets (Where X is the window size). Sender then waits for ACK from receiver. When it receives ACK for packet 1, sender sends packet X+1. When sender receives ACK for packet 2, it sends packet X+2. If sender times out waiting for an ACK, sender resends that packet.
If you want to be true to the TCP, then you would initiate a connection with a 3 way handshake. The handshake works like:
Connection initiator chooses sequence number SEQA, and sends packet to server with SEQ=SEQA. Server chooses sequance number SEQB, and sends packet back with ACK=SEQA, and SEQ=SEQB. Connection initiator then sends back packet with SEQ=SEQA+1, and ACK=SEQB+1.
TCP also has some flags which are used in initiating or tearing down connections, but they probably wont be needed for what you are trying to do. You can always do a search to figure out what these flags are, and when they are used though.
Also consider the difference between dropping and denying packets
http://logi.cc/linux/reject_or_deny.html
Monday - what a way to spend a seventh of your life