PDA

View Full Version : winpcap-dev+pthread+pcapplusplus makes qt window do not appear



Eyre
17th March 2017, 16:41
Hello, folks.

Here I have a problem.
I was planning to make some kind of sniffer, just for practising. And so I started facing problems from the setup.

So, basically program does not start.

.pro file




#-------------------------------------------------
#
# Project created by QtCreator 2017-03-16T17:23:52
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = untitled
TEMPLATE = app
#CONFIG += c++11
INCLUDEPATH += E:/lib/PcapPlusPlus-17.02-windows-mingw32-gcc-5.3.0/header
LIBS += E:/lib/PcapPlusPlus-17.02-windows-mingw32-gcc-5.3.0/Pcap++.lib
LIBS += E:/lib/PcapPlusPlus-17.02-windows-mingw32-gcc-5.3.0/Packet++.lib
LIBS += E:/lib/PcapPlusPlus-17.02-windows-mingw32-gcc-5.3.0/Common++.lib

INCLUDEPATH += E:/lib/WpdPack/Include
LIBS += -LE:/lib/WpdPack/Lib -lwpcap -lpacket
LIBS += -lpthread
LIBS += -lws2_32
LIBS += -liphlpapi
LIBS += -static-libgcc -static-libstdc++

SOURCES += main.cpp\
sniffer.cpp

HEADERS += sniffer.h

FORMS += sniffer.ui




then goes sniffer.h



#ifndef SNIFFER_H
#define SNIFFER_H
#include <winsock2.h>
#include <QMainWindow>

namespace Ui {
class Sniffer;
}

class Sniffer : public QMainWindow
{
Q_OBJECT

public:
explicit Sniffer(QWidget *parent = 0);
~Sniffer();

private slots:
void on_pushButton_2_clicked();

private:
Ui::Sniffer *ui;
};

#endif // SNIFFER_H



.cpp




#include "sniffer.h"
#include "ui_sniffer.h"

#include <MacAddress.h>
#include <IpAddress.h>
#include <PlatformSpecificUtils.h>
#include <PcapLiveDeviceList.h>
#include <PcapLiveDevice.h>
#include <EthLayer.h>
#include <ArpLayer.h>
#include <Logger.h>
#include <QMessageBox>

using namespace pcpp;
Sniffer::Sniffer(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Sniffer)
{
ui->setupUi(this);
}

Sniffer::~Sniffer()
{
delete ui;
}

void Sniffer::on_pushButton_2_clicked()
{
const std::vector <PcapLiveDevice*>& a = PcapLiveDeviceList::getInstance().getPcapLiveDevic esList();
/*QString showme(*a[0]->getName());
QMessageBox::information(this, "info",showme);*/
}




and main




#include "sniffer.h"
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Sniffer w;
w.show();

return a.exec();
}





so there's just 1 button and some headers.

I was using dll for pthreads from somewhere here

https://sourceforge.net/p/mingw-w64/wiki2/Compile%20pthreads/

which I copied to /mingw53_32/bin

precompiled pcapplusplus from.. here

http://seladb.github.io/PcapPlusPlus-Doc/download.html

and winpcap-dev from their site.

when I try to run the app, it appears in memory, visible in taskmgr, but window with my fancy button doesn't show.

Hope to your assistance, folks :)

Eyre
21st March 2017, 11:19
And yes, working with developer of the PcapPlusPlus I figured out what was that. The thing is in some moment something went wrong to my environment, because my project was compiled and ran from the first time by dev without changes. So I created vm using wmvare with the same windows distribution (win7x64Ent), installed qt in it, placed libs and so everything just started to work with the first try.


void Sniffer::on_pushButton_2_clicked()
{
const std::vector <PcapLiveDevice*>& a = PcapLiveDeviceList::getInstance().getPcapLiveDevic esList();
for (auto it:a)
QMessageBox::information(this, QString(it->getMacAddress().toString().c_str()),QString(it->getName()));
}


so this code runs like this:

12398

So I would highly recommend to use vm or the whole clean system installation with the only qt|compiler instance in development. or at least have it, to test in good-working environment. Thanks for all views, hope this information will be helpful. And by the way, almost the same problem reports was found in this and some other forums, the guys was encountered almost the same problem but they have dependency-walker error messages about libraries with different cpu types. So they solved it by clean reinstallation of Qt and editing windows path variable to default when installing and then running project. That's all I have for now. Cheers.