Pcap, the packet Capture library, grabs the package library and provides a high-level interface to the capture system. All packets on the network, even those sent to other hosts, can be captured through this mechanism. It also supports saving captured packets as local files and reading information from local files.
There are a few more details to refer to: http://baike.baidu.com/view/6584893.htm
Some introductions of Libpcap, http://baike.baidu.com/view/1319961.htm
And this is libpcap download information http://www.tcpdump.org/release/
There are some steps or installation errors that can be referred to here: http://blog.csdn.net/cfjtaishan/article/details/7096085
To summarize:
1, install the GCC compiler (if installed, you can avoid)
2, Libpcap has some dependent packages, so you have to install the GNU M4,bison and flex in turn before installing Libpacap:sudo apt-get install flex and sudo apt-get Install Bison )
3, the download of these several installation package extracted to the same directory, the terminal under the root identity in turn into the above 4 folders. Perform the following command to compile the installation, respectively:
./configure
Make
Make install
4, test code (turn from: http://hi.baidu.com/amauri3389/item/0982a400359cb9d51ef04668)
#include <stdio.h>Int main () {char *dev,errbuf[ 1024pcap_lookupdev (ERRBUF); if (Dev==null) {fprintf (stderr, "coundn ' t find default device:%s \n ",errbuf); return 2 "device:%s \n" ,dev); return 0
Compile: gcc-o test Test.c-lpcap (may appear
HERE.C: In the function ' main ':
Here.c:12:5: Warning: Assigning integers to pointers, not type conversions [enabled by default]
Message, leave it, and proceed to the next step.)
Execution: When executing, the password is also entered as root, sudo su
The./test executes the generated executable file test.
Next comes the problem that I have encountered:
Tip: Error while loading shared Libraries:libpcap.so.1:cannot open Shared object file:no such file or DIRECTORY
Workaround: Open the file ld.so.conf in the/etc directory and add two lines
/usr/local/lib
/usr/lib
then execute the commands from the new load configuration under the terminal: ldconfig
OK, then compile and run test.c successfully output the result:
Device:eth0
If not executed as root, the output will be:
Couldn ' t find default Device:no suitable device found
Attached: Some bison reference and study materials: Http://zh.wikipedia.org/wiki/GNU_bison
Http://wenku.baidu.com/view/6501c928bd64783e09122ba1.html
Installation of Pcap