Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems finding pcap.h and linking

I'm working on Fedora 17 and I want to program with libpcap. The problem is that my computer isn't finding pcap.h, which is really wierd since I've installed libpcap and libpcap-devel. Also wireshark and snort works on my station which I believe uses that library. So when I compile my code with ...

#include <pcap.h>
... Code

And use gcc my_file.c -lpcap, I get compiler errors that say ... can't find pcap.h. Whats odd is that I see my libpcap.so files in /libraries/ directory. I've done ..

yum install libpcap and yum install libpcap-devel

I don't know why Fedora is doing this to me.

Thanks for any help!

like image 863
Dr.Knowitall Avatar asked Nov 12 '12 01:11

Dr.Knowitall


3 Answers

Your library might be missing, install it and link it

yum install libpcap-devel

In your makefile add:

-L/usr/lib -lpcap
like image 200
GoTTimw Avatar answered Sep 28 '22 12:09

GoTTimw


Try

~$ whereis pcap

Then as mata said

gcc -lpcap -I{path} file.c

where {path} is the path that whereis gave you, you will choose the one with the pcap.h substring at the end (without the pcap.h part).

like image 28
yeyo Avatar answered Sep 28 '22 12:09

yeyo


You'll have to specify the folder where the headers are installed, for example:

gcc -I/usr/include/pcap my_file.c -lpcap

Try locate pcap.h to find the right directory to use with the -I switch.

like image 44
mata Avatar answered Sep 28 '22 12:09

mata