Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

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,
Dinesh.
0
dineshb_2001
Asked:
dineshb_2001
2 Solutions
 
mugman21Commented:
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.

http://sourceforge.net/projects/libpcap/

Mugman
0
 
ostdpCommented:
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 ...

http://security.royans.net/info/rawip/code/rawip1.shtml
0
 
dineshb_2001Author Commented:
Hello,

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


Dinesh.
0
 
amanchennaCommented:
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.

http://www.cet.nau.edu/~mc8/Socket/Tutorials/section1.html
http://post.doit.wisc.edu/library/aix51/usr/share/man/info/en_US/a_doc_lib/aixprggd/progcomc/ch13_libpcap.htm#HDRAA427LIBKSQ
http://www.tcpdump.org/pcap.htm

may be these helps u.

Aman.
0
 
mugman21Commented:
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.

Mugman

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now