Keywordslibpcap library linux install libpcap ubuntu libpcap ubuntu
In the past two days, the company asked me to learn about pcap, but I still don’t know what it does. First, I found out from the Internet that pcap is actually a packet capture library. This packet capture library provides a high-level interface to the packet capture system. All data packets on the network, even those sent to other hosts, can be captured through this mechanism. It also supports saving captured data packets as local files and reading information from local files. It is further understood that the library under linux is libpcap, which is a network packet capture function package under the unix/linux platform, and most network monitoring software is based on it. Corresponding to the version of the winpcap library under windows.
Simple Application Server USD1.00 New User Coupon
* Only 3,000 coupons available.
* Each new user can only get one coupon(except users from distributors).
* The coupon is valid for 30 days from the date of receipt.
First of all, it needs to be in a newest libpcap source file. I downloaded the latest version libpcap-1.2.0, and then decompressed it to the user directory.
In the Linux system, installation only requires three steps: 1. ./configure; 2. make; 3. make install.
In the process of installing according to these three parts, two problems were encountered, which were errors in the installation process. These errors are because there is no corresponding tool. I list the errors and solutions as follows, and share them with you:
The first step, an error like this occurred during the configuration process: ./configure:error: Your operating system's lex is insufficient to compile libpcap. It means that the lexical analyzer (lex) of your operating system is insufficient to compile libpcap. You can Baidu for detailed information about this lex. Then I checked the information, the solution is to install a flex, sudo apt-get install flex and press Enter. After installing this, you can pass, generate Makefile files and other configuration files.
In the second step, an error was encountered during make compilation: the make:yacc: command was not found. Yacc (Yet Another Compiler Compiler) is a compiler (compiler code generator) used to generate a compiler on unix/linux. The compiler generated by yacc uses a parser written in C language, which needs to be used together with the lexical analyzer lex, and then compile the C programs generated by the two parts together. The solution to this problem is to install bison. For detailed information on bison, here is not too long. sudo apt-get install bison. Also pay attention to a problem, some files may have permission requirements during compilation, so it is best to use the sudo make command.
The third step, make install installation. There was no problem at this step. But it is also best to use sudo make install.
The next step is to use this libpcap library.
After the installation is successful, when using the library to compile or execute the compiled executable file, you may encounter the following problems:
1. Compile time: For example,
gcc packet.o -lpcap -lpthread /* -lpcap is used to call the libpcap library, so don't forget to add it. */
/usr/local/lib/libpcap.so: undefined reference to `pcap_parse’
collect2: ld returned 1 exit status
For such error messages, first confirm whether libpcap-dev is installed, if not, you can install it first: sudo apt-get install libpcap-dev; I tried to install this and the problem was not resolved, but I am not sure about the following Whether the method has anything to do with this step, I tried this plan first, but it didn't work in the end.
Then the following solution is really hard to think of: reinstall the libpcap library. Enter the decompressed library directory, first make clean, and then install it again: 1. ./configure; 2. make; 3. make install; the problem is solved. It is difficult for us to think of this solution. The specific reason remains to be studied.
2. When executing: For example,
After the compilation is passed, an executable file is generated: a.out, and then executed in the terminal: sudo ./a.out, the following error message appears:
error while loading shared libraries: libpcap.so.1: cannot open shared object file: No such file or directory
The solution is: change the name of the /usr/lib/libpcap.so library file to libpcap.so.1. Of course, you can also create a soft link for libpcap.so.1: ln -s /usr/lib/libpcap.so /usr/lib/libpcap.so.1; this will solve the problem.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.