Use libpcap in Fedora

Source: Internet
Author: User
Fedora generally comes with libpcap, but it lacks pcap. h, so you need to install yuminstalllibpcap * And then locate it to see if it is a small program found online under/usr/lib: // test. c # include # includeintmain (intargc, char * argv []) {char * dev, errbuf [PCAP_ERRBUF_SIZ Fedora generally comes with libpcap, but pcap is missing. h, so install
Yum install libpcap *
After that, locate the file to check whether it is under/usr/lib.
Small programs found online:
// Test. c
# Include
# Include
Int main (int argc, char * argv [])
{
Char * dev, errbuf [PCAP_ERRBUF_SIZE];
Dev = pcap_lookupdev (errbuf );
If (dev = NULL)
{
Fprintf (stderr, "can't find default device: % s \ n", errbuf );
Return 2;
}
Printf ("device: % s \ n", dev );
Return 0;
}
Compilation: gcc test. c-lpcap
No error is reported, but an error occurs during running:
./A. out: error while loading shared libraries: libpcap. so.1: cannot open shared object file: No such file or directory
Ldconfig:/usr/lib/libnet. so.1 is not a symbolic link
I guess the libpcap and libnet versions are incorrect ?? I don't know ...... I hate soft links ...... When compiling a counterfeit package program, the link from the libnet library killed me ......
Look...
[Root @ localhost ~] # Locate libnet. so.1
/Root/libnet-1.1.4/src/. libs/libnet. so.1
/Root/libnet-1.1.4/src/. libs/libnet. so.1.5.0
/Usr/lib/libnet. so.1
/Usr/lib/libnet. so.1.5.0
/Usr/local/include/libnet. so.1.5.0
/Usr/local/lib/libnet. so.1
/Usr/local/lib/libnet. so.1.5.0
Go to/usr/local/lib to check how the link is linked:
[Root @ localhost lib] # ll | grep libnet. so
Lrwxrwxrwx 1 root 15 2010-09-03 07:36 libnet. so-> libnet. so.1.5.0
Lrwxrwxrwx 1 root 15 2010-09-03 07:36 libnet. so.1-> libnet. so.1.5.0
-Rwxr-xr-x 1 root 324919 2010-09-03 07:36 libnet. so.1.5.0
Okay, go to/usr/lib and follow the link ......
[Root @ localhost lib] # ln-s libnet. so.1.5.0 libnet. so.1
Look at it, right ......
[Root @ localhost lib] # ll | grep libnet. so
-Rwxr-xr-x 1 root 324919 2010-09-03 07:53 libnet. so
Lrwxrwxrwx 1 root 15 2010-09-12 libnet. so.1-> libnet. so.1.5.0
-Rwxr-xr-x 1 root 324919 2010-09-03 07:53 libnet. so.1.5.0
[Root @ localhost lib] # ldconfig is correct.
Return to the directory test. c, pray, and compile it again.
Run:
[Root @ localhost ~] #./A. out
Device: eth0
Inniu ......
Install the required software package libpcap0.8-dev. Note that it is the dev package instead of libpcap0.8, because we need the required header file for development.
During compilation, you must specify the compilation Link Library.
# Gcc get_a_packet_code.c-o get_a_packet_code-lpcap

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.