Install libpcap on Ubuntu

Source: Internet
Author: User
You can learn about the basic installation environment through official materials: Tocompilethelibpcaplibrary, yourUnixdistributionmusthaveaCcompiler, andthelexandbisontextparsers. ForOpenSourceUnixdistributionssuchasLinuxandFreeBSD, t

You can learn about the basic installation environment through official materials:
To compile the libpcap library, your Unix distribution must have a C compiler, and the lex and bison text parsers. for Open Source Unix distributions such as Linux and FreeBSD, the gcc, flex, and bison programs provide these functions.
C compiler, flex, and bison are not installed after the Ubuntu operating system is installed.

1. Install the gcc compiler
Run the sudo apt-get install gcc libc6-dev directly on the terminal to install the gcc( ), to compile all the simple helloworld, then the error "C compiler cannot create executable" is prompted when compiling the tar.gz file.

Compile helloworld to test the gcc compiler:
# Include
Int main (){
Printf ("hello, world! \ N ");
Return 0;
}

The first time I came into contact with the gcc compiler, I found that main functions such as void main () are not supported.

2. Compile GNU M4 (version 1.4)
This is an essential environment for compiling flex. Otherwise, the error "GNU M4 1.4 is required" will be prompted.

3. Compile flex (version 2.5.33)
If no flex is available, the system prompts "Your operating system's lex is insufficient to compile libpcap" When libpcap is directly installed.

4. Compile bison (version 2.3)
If you install libpcap directly after flex is installed, the error "don't have both flex and bison; reverting to lex/yacc" is returned. If flex is installed earlier, bison must be used together.

5. Compile libpcap
After completing the four steps, you can use the following three commands to install the libpcap environment:
./Configure
Make
Make install

A simple example is to test libpcap:
// Device. c
# Include
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-lpca must be used during compilation. Otherwise, the error "pcap_lookupdev undefined reference" will be prompted.

Run the command:./device

6. Summary
Just a few simple steps, I took a day to get it out. I went abroad to check a lot of information, and almost couldn't find this information in China, one of the main reasons is that there are few people using Ubuntu, but you can directly install it using RedHat, without the lack of flex and bison in your system. The other is that I am not familiar with the installation program on the linux platform, unlike windows platforms that can be installed with just a few mouse clicks, flex and bison are hard to find a place to provide download, which is also abroad.

Note:
1) The error "failed to create general file '/usr/local/bin/m4': Permission denied" occurs. Permission is incorrect. Ubuntu is disabled by default by root users, you can use the sudo command to solve this problem.

2) Ubuntu does not support rpm installation files. rpm is the standard Installation File Format of the Red Hat operating system. You can use alien to convert the rpm package to the deb package.
Install alien: sudo apt-get install alien
Alien: alien *****. rpm
In this way, ***. deb supported by Ubuntu is generated.
Install deb: sudo dpkg-I *****. deb
Or right-click the menu to install deb

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.