CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2002
    Location
    Germany
    Posts
    451

    How to retrieve TCP header?

    Hello,

    Is there anybody knowing how to retrieve the TCP header (I am particulary interested int the Source port, perhaps checksum and flags).

  2. #2
    Join Date
    Dec 2002
    Posts
    287
    Do you really need to look at the IP packets or you just need to know where the packet is coming from ?
    For the first part you can use libpcap to capture all the packets and then analyze them.
    For the second part you can use getpeername:

    http://msdn.microsoft.com/library/de...peername_2.asp

    Dan

  3. #3
    Join Date
    May 2002
    Location
    Germany
    Posts
    451
    I really do need TCP socket level information, so this stuff does not really help me. Both for UNIX and Windows.

  4. #4
    Join Date
    Dec 2002
    Posts
    287
    Can you be a little bit more specific about the problem you are tring to solve ?

    Do you have an existing connection and a socket and you want to capture all the packets that are coming on that socket and look at the TCP header ?

    Dan

  5. #5
    Join Date
    May 2002
    Location
    Germany
    Posts
    451
    Yes. I have an existing connection (created by a connect call) and I would like to retrieve the header of each TCP packets (the same what you can see in Sniffer).

  6. #6
    Join Date
    Dec 2002
    Posts
    287
    Since any socket read operation can read more or less than one packet at a time, I don't believe there is a way to get the header at the time when you do a read. But I think you should be able to achieve this by using libpcap and changing it so it doesn't set the ethernet adapetr in promiscous mode (just to avoid extra processing). Then set up another thread that is doing pcap_loop and choose only the packets that have the source equal to the remote address & port.

    Kind of complicated but I don't know other solution right now.

    Dan

  7. #7
    Join Date
    May 2002
    Location
    Germany
    Posts
    451
    Seems difficult. My boss is a network specialist for about 15 years and he designed a very complicated protocol sitting on TCP.

    BTW, is this libpcap available for UNIX and windows too?

  8. #8
    Join Date
    Dec 2002
    Posts
    287
    Yes, it is available both on Windows and UNIX - I think it is called winpcap on Windows.
    What is the reason why you want see the packet headers ?

    Dan

  9. #9
    Join Date
    May 2002
    Location
    Germany
    Posts
    451
    I will try it, perhaps on Monday.

    The reason is a long story and finally the technical project manager (who is not a programmer) decided to use it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured