0

I want to create an application by libpcap in Qt in Kali linux. I create similar application in windows & does work.

I download & install libpcap. Now, Qt recognizes pcap.h but some functions & constants does not work. like as:

pcap_open - PCAP_OPENFLAG_PROMISCUOUS - pcap_findalldevs_ex - PCAP_SRC_IF_STRING - _snprintf_s.

The compiler errors similar as 'sth' was not declared in this scope. I use below headers but above errors apppear.

#define HAVE_REMOTE
#define WPCAP
#include <pcap.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

3 Answers3

1

add LIBS += -lpcap at the end of your .pro file. It will solve the issue.

Sigcont
  • 717
  • 2
  • 8
  • 16
  • Thanks a lot dear @Startup. I added this but the project does not run. in application output: /root/Qt-Project/build-LinuxBasedPacketCapturing-Desktop_Qt_5_2_1_GCC_32bit-Debug/LinuxBasedPacketCapturing: error while loading shared libraries: libpcap.so.1: cannot open shared object file: No such file or directory – Mohammad Reza Ramezani Mar 24 '14 at 05:12
  • @Mohammad apt-get install libsqlite3-dev, check your /usr/lib whether libpcap.so is present there or not. other wise you have to link the location of libpcap.so – Sigcont Mar 24 '14 at 05:14
  • I uesd locate command in linux & responds. some of response is here: /usr/lib/i386-linux-gnu/libpcap.so.0.8 /usr/lib/i386-linux-gnu/libpcap.so.1.3.0 I added LIBS += -L/usr/lib/i386-linux-gnu/libpcap.so.1.3.0 but the application output says like above. – Mohammad Reza Ramezani Mar 24 '14 at 05:24
  • ls /usr/lib | grep libpcap , check libpacp versio, it will display libpcap.so.1.3.0 or something else then ln -s /usr/lib/libpcap.so.1.3.0 libpcap.so.1. try it may solve your issue – Sigcont Mar 24 '14 at 05:32
  • Exccuse me. I was testing on wrong project. the errors of My first post does not solve. I think above founctions & constant are not compatible with libpcap (just in winpcap). because another functions workes. Right? – Mohammad Reza Ramezani Mar 24 '14 at 05:42
  • "I think above founctions & constant are not compatible with libpcap (just in winpcap). because another functions workes. Right?" Yes. See my answer. –  Mar 24 '14 at 21:51
1

WinPcap adds some APIs not available in libpcap (and versions of libpcap newer than the version upon which the latest WinPcap release is based have APIs not available in WinPcap).

pcap_open() is one of those APIs; it is NOT available in libpcap. You must either use pcap_open_live() or, in libpcap 1.x, pcap_create() and pcap_activate().

libpcap also doesn't currently support remote packet capture.

0

I searched & found some functions in winpcap does not work in libpcap (As Guy Harris said).

For Qt programmer in linux, they have to add below code to .pro file:

LIBS += -L/usr/local/lib/ -lpcap
BenMorel
  • 34,448
  • 50
  • 182
  • 322