Thread: reading packet headers

  1. #1
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385

    reading packet headers

    I have written a simple program that watches a port (using an AF_INET socket) and prints out the contents of the TCP packet. The thing is i would also like to read the header information aswell (source IP and port and destination IP and port).

    Do i need to use a different type of socket (ie not AF_INET)?
    Should i be using raw sockets to do this or do i need to work at a lower level, at the moment i am at the application layer so the underlying layers are stripping the data i want.

    Can someone please point in the right dircetion?

    tia

    (writing in C , compiling for Slackware/10 with gcc)
    Monday - what a way to spend a seventh of your life

  2. #2
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    I just searched the internet for you, I found that raw sockets may or may not include the headers. I found this explaining some stuff about packets. They recomment an api such as libpcap to capture packets.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    I've used libpcap before, and it works great. It's extremely easy to use as well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading wmv
    By kryptkat in forum C Programming
    Replies: 4
    Last Post: 01-25-2008, 05:06 PM
  2. Replies: 6
    Last Post: 04-28-2006, 12:06 PM
  3. Networking (queuing delay, avg packet loss)
    By spoon_ in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-05-2005, 11:23 AM
  4. packet analyzer in c
    By althagafi in forum Networking/Device Communication
    Replies: 16
    Last Post: 08-06-2004, 03:35 PM
  5. packet analyzer in c
    By althagafi in forum C Programming
    Replies: 1
    Last Post: 07-26-2004, 11:46 PM