Thread: Packet Reading Strategy

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Newport, South Wales, UK

    Packet Reading Strategy


    I was wondering if peeps could give me an idea about how to read complete/incomplete packets out of a receive buffer.

    At the moment, I'm just passing the entire buffer to the validation function, which checks reported size against buffer length, checksum etc. The problem is when the buffer contains a fragment of a packet yet to be fully received, this is currently being discarded as erroneous but obviously that's not good as the peer then has to retransmit, blah blah blah.

    I'm having one of my mental block periods at the moment, but would it go something like:-
    Read as many valid packets as possible until you come across one that has bad size field
    Copy from this point in the buffer back to the start
    Read into buffer address + part packet length

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    do you have a packet length in the packet header?
    In this case you can retry reading till you achieve the required number of bytes...
    And only then process the decoding
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Packet processing in Socket programming, please help
    By pumpkin in forum Networking/Device Communication
    Replies: 5
    Last Post: 05-28-2009, 01:33 AM
  2. Replies: 4
    Last Post: 05-05-2009, 05:35 AM
  3. How to make a Packet sniffer/filter?
    By shown in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2009, 09:51 PM
  4. question about reading files in
    By smd in forum C++ Programming
    Replies: 11
    Last Post: 08-25-2003, 07:40 PM
  5. problems reading data into an array and printing output
    By serino78 in forum C Programming
    Replies: 4
    Last Post: 04-28-2003, 08:39 AM