Reading a packet

Posted on 2004-11-24
Last Modified: 2010-04-17
Hi all,

 My laptop is connected to a network. I am writing a program in C (LINUX) in linux environment which reads the packets received by my laptop and evaluating the information in the packet. But I am stuck in the initial stage itself how to read a packet. I know ethereal tool but I want to write my own code to read a packet.

Please can anyone tell me in programming guidelines how to read a packet and store the information it contains and also to check what data it has.

Someone specifying links to this topic is also appreciated.

please reply me asap,
thanks in advance,
Question by:dineshb_2001
    LVL 8

    Accepted Solution

    uhm, that is a lot of coding..... To much for this forum.... Take a look at libpcap. It's open source, designed for what your looking to do, and will show you exactly what to do from the development point of view.

    LVL 4

    Assisted Solution

    If you don't want to go down the route of writing a packet capture driver (which is of course the right way to go about it, but it is also very .. shall we say work intensive) you could possibly get away with using raw sockets. (see link below). Depending on your app it may or may not be suitable ...

    Author Comment


    can u suggest me the books or links where we can learn how to program for capturing packets.


    Expert Comment

    Hi dineshb,

    check the following though I posted the comment for the same question of urs in another thread.

    Here r the best sites for writing a program to capture a packet using pcap library.

    may be these helps u.

    LVL 8

    Expert Comment

    As I stated above, I believe the libpcap library is the correct path to follow. Not only does it perform the required task of capturing packets, but it is also portable between the linux and windows enviroments (libpcap or winpcap).

    Furthermore, libpcap has been used by hundreds of applications over a period of several years and is a proven method. My initial response pointed to the dev link which contains the source for the library which would allow any experianced programmer to understand the methods and techniques used to capture packets.

    Basically the question was how to capture packets on a linux box; the link to the source code of libpcap I provided above demonstrates how too.



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Javascript: Crash Course

    Javascript is not only emerging as the most important language to know, it's flexibility is unique. With Javascript being deployed on the web, mobile and even the desktop this is the one language that all technologists need to know.

    Suggested Solutions

    This article is filled with multiple code samples and explanations for mathematical calculations. They are as follows: 1. General tips 2. Quadratic formula 3. Object collision 4. Projectile path General Tips       Here are some of my tips f…
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now