1. Install GCC:
Yum-y install gcc-C ++
2. Install flex:
Yum-y install flex
If no flex is available, the system prompts "your operating system's Lex is insufficient to compile libpcap" When libpcap is directly installed;
3. Install bison
Yum-y install bison
If Flex is installed earlier, Bison is required. If the message "don't have both flex and bison; reverting to lex/YACC" is not displayed;
4. Install libpcap
: Http://www.tcpdump.org/
Download version: wget-C http://www.tcpdump.org/release/libpcap-1.5.3.tar.gz
Decompress package: Tar zxf libpcap-1.0.0.tar.gz
Enter the decompressed directory and enter the command line:
The command is as follows:
./Configure
Make
Make install
5. A simple example to test libpcap:
// Device. c
# Include <stdio. h>
# Include <pcap. h>
Int main (INT argc, char * argv []) {
Char * Dev, errbuf [pcap_errbuf_size];
Dev = pcap_lookupdev (errbuf );
If (Dev = NULL ){
Fprintf (stderr, "couldn't find default device: % s \ n", errbuf );
Return (2 );
}
Printf ("device: % s \ n", Dev );
Return (0 );
}
Compilation command: gcc-O device. C-lpcap
Note: libpcap parameter-lpcap should be used during compilation; otherwise, the error "pcap_lookupdev undefined reference" will be prompted;
Run the command:./Device
Reprinted: http://www.tcpdump.org/release/libpcap-1.5.3.tar.gz
Http://blog.sina.com.cn/s/blog_6f289b0e01014jst.html
Solution to running errors:
Error while loading shared libraries: Libpcap. so.1: cannot open shared object file: no such file or
//-----------------------------------------------------------
// Author: lanyang123456
// Date: 2011-11-10
//-----------------------------------------------------------
In Linux, The libpcap library is required to run the sniff program.
First download and install the library,: http://www.tcpdump.org/
Click downloads
After download
(1) Extract
(2) enter the file directory after decompression,./configure
(3) make install
Default installation directory/usr/local/lib
When the sniff program passes the compilation and runs the sniff program, the following error occurs:
./SN: Error while loadingshared libraries: Libpcap. so.1: cannot open shared object file: no such file ordirectory
Because libpcap has been installed, the program cannot find the location of the library.
Solution:
Add the directory of Libpcap. so.1 to the/etc/lD. So. conf file,
Open the lD. So. conf file and add a line/usr/local/lib:
Includeld. So. conf. d/*. conf // original content
/Usr/local/lib
Save and run ldconfig on the terminal.
Run the sniff program again. OK.
Sometimes decompress the file with tar. The error is as follows:
Gzip: stdin: unexpectedend of file tar: Unexpected EOF in archive tar: error is not recoverable: exiting now
Cause:
The file is damaged and downloaded again.
Reprinted: http://blog.csdn.net/lanyang123456/article/details/6956093