Reading a packet

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,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 ...
dineshb_2001Author Commented:

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

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.

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.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.