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?


are there any good ways to get the tcp header of a received tcp packet?
The sockets library's purpose is to hide all that stuff from you. You need to act as a sniffer to see the stuff you're interested in (or use a different networking library).

If you want to act as a sniffer, use libpcap. You can intelligently filter waht you see.
Topic archived. No new replies allowed.