[Learning] How to use Libpcap library in Qt
-
h1. How to use Libpcap library in Qt
h2. Getting Start
Note that I do this in Ubuntu operating system, in Windows you can use from Winpcap library.
-
Step 1: Install libpcap using below command:
@sudo apt-get install libpcap-dev@ -
Step 2: Run Qt Creator as super user (my Qt path: /opt/Qt5.3.1/Tools/QtCreator/bin)
@cd /opt/Qt5.3.1/Tools/QtCreator/bin
sudo -b ./qtcreator@ -
Step 3: Add library to project: first open [your_project_name].pro file in Qt Creator and add this line:
@LIBS += -lpcap@ -
Step 4: (Example) Print your device(s) name:
@#include <QDebug>
#include <pcap.h>@
@pcap_if *alldevs;
pcap_if_t *d;
char errbuf[PCAP_ERRBUF_SIZE+1];
if (pcap_findalldevs(&alldevs,errbuf)!=-1)
{
QStringList retval;
for(d=alldevs;d;d=d->next)
qDebug()<<QString(d->name);
}//more: http://www.programming-pcap.aldabaknocking.com/@
- Step 5: Enjoy :) [Written by Ali Jafarabdi :: Qt is an awesome programming language.]
-
-
as soon as posible i post new thread with Qt libraries which this thread is referred in it ;)
-
hi thanks for your topic, i have some more question about pcab , can u tell me how can i run this type of program in qt , in ubunto as administrator , and how to learn more??