Thread: How to drop a packet when using sockets (Urgent)

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    2

    Question How to drop a packet when using sockets (Urgent)

    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?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    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.

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    2
    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.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    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.

  5. #5
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-05-2009, 05:35 AM
  2. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  3. Raw Packet (sorry tripple weird Post)
    By Coder87C in forum Networking/Device Communication
    Replies: 6
    Last Post: 03-04-2006, 11:34 AM
  4. multiple UDP sockets with select()
    By nkhambal in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-17-2006, 07:36 PM
  5. Packet Filter Using Unix Sockets
    By doraiashok in forum C Programming
    Replies: 3
    Last Post: 12-12-2003, 02:56 PM