Find the answer to your Linux question:
Results 1 to 2 of 2
I want to get the TCP header of each received TCP packet (destined for a specific program,namely, a port) it seems not possible to use recv() or recvfrom() to get ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2012
    Posts
    87

    how to get the tcp header of a received packet in socket programming?


    I want to get the TCP header of each received TCP packet (destined for a specific program,namely, a port)
    it seems not possible to use recv() or recvfrom() to get the TCP header using regular socket.

    So, I want to use raw socket
    with raw socket, I can use recvfrom() to receive all IP packets destined to the host
    if the host receives a lot packets,
    I need to check the port number of each packet so see whether it is the needed.
    then it could be very time and CPU comsuming?
    Code:
        while()
        {
        recvfrom();
        check_port_number(); 
        }
    are there any good ways to get the tcp header of a received tcp packet?

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,556
    Install the pcap libraries, and you can use those to look at the raw packets in your program, or you can use wireshark (uses the pcap libs) with the appropriate filters to capture and look at those packets.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

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