Results 1 to 7 of 7

Thread: Container for TCP segments

  1. #1
    Join Date
    May 2012
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Container for TCP segments

    Hello,

    I am looking for a container in which I could store TCP segments sorted by TCP connection ID (quint32 srcIP, quint16 srcPort, quint32 dstIP, quint16 dstPort), and by sequence number. TCP segments would be added individually to container, but deleted would be every TCP segement from TCP connection in which FIN segment appear.
    What container would be the best for that?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Container for TCP segments

    How about you share your thoughts on how you might approach it?

  3. #3
    Join Date
    May 2012
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Wink Re: Container for TCP segments

    I thought about QHash<TCPConnectionID, QMap<quint32, TCPSegment*> >, but I did not want to impose my idea, because someone with fresh approach to the problem could suggest something simpler and better. QMap key would be Sequence Number of TCP segment.
    Last edited by morfis; 28th May 2012 at 21:00.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Container for TCP segments

    I ask because some people expect answers, sometimes for school homework, with no intellectual effort on their part. You clearly thought about it.

    That seems like a reasonable approach for many connections (overkill for two or three) if you only ever search on a complete TCPConnectionID, which I assume is a simple struct of address/port pairs, and are careful not to accidentally insert null entries in the map (using the operator[]). If you know something about the traffic you are monitoring, like 99.9% of connections send less than 10 segments, then the inner map may be a simple QVector<TCPSegment*>.

    If you need to be able to find all connections to with a particular source address/port, or just using port x, this structure will not be useful because of the hashing function.

  5. #5
    Join Date
    May 2012
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Container for TCP segments

    But I have a problem with mentioned container- every time I insert segment to inner QMap I have to copy whole inner QMap from outer QHash, insert segment to it and insert whole QMap to QHash. Is it possible to insert TCPSegment without copying inner table?
    Qt Code:
    1. TCPConnectionID connectionID(srcIP,srcPort,dstIP,dstPort);
    2. QMap<quint32, TCPSegment*> tcpSegmentMap = tcpConnectionHash.value(connectionID);
    3. tcpSegmentMap.insertMulti(segment.sequenceNumber(),new TCPSegment(...));
    4. tcpConnectionHash.insert(connectionID,tcpSegmentMap);
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Container for TCP segments

    If you use tcpConnectionHash[key] you get a non-const reference to the map, so:
    Qt Code:
    1. QHash<TCPConnectionID, QMap<quint32, TCPSegment*> > cache;
    2. TCPConnectionID connectionID(1,2,3,4);
    3. quint32 fakeSegNo = 123;
    4. TCPSegment *fakeSeg = 0;
    5. cache[connectionID].insert(fakeSegNo, fakeSeg);
    To copy to clipboard, switch view to plain text mode 
    Do not use operator[] if you just want to check if a key exists.

    Are you using insertMulti() because you are expecting more than one segment for a given segment number on a single connection?

  7. The following user says thank you to ChrisW67 for this useful post:

    morfis (31st May 2012)

  8. #7
    Join Date
    May 2012
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Container for TCP segments

    If there is no data in segment (but there is a TCP header) and it is not SYN or FIN segment, sequence number of next segment is not incremented. So yes, I expect at present multiple segments with the same sequence number. I will have to consider this.

    Thank you for help.

Similar Threads

  1. Suggest me a container
    By giantdragon in forum Newbie
    Replies: 6
    Last Post: 12th September 2011, 10:44
  2. drawing clothoid segments
    By schmimona in forum Qt Programming
    Replies: 6
    Last Post: 31st July 2011, 12:03
  3. Drawing multiple line segments
    By twells5 in forum Qt Programming
    Replies: 8
    Last Post: 3rd June 2011, 14:23
  4. Replies: 1
    Last Post: 6th May 2009, 15:29
  5. Quick ? about qSort(Container & container)
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2007, 11:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.