User Tools

Site Tools


programming:qt

This is an old revision of the document!


Qt

Get Qt from https://www.qt.io/download.

For Qt in Python, see PyQt5 Tutorial

Using WinPcap with Qt

qt5_winpcap.cpp
// If using qt creator, add these
// to the project file in Windows
// 
//# Pcap specific build stuff for Windows (in qmake)
//INCLUDEPATH += C:/WpdPack/Include
//LIBS += C:/WpdPack/Lib/wpcap.lib
//LIBS += C:/WpdPack/Lib/Packet.lib
//CONFIG += no_lflags_merge
//
//# Fixes the missing inet_to_ntoa
//LIBS += -lws2_32
 
 
 
#define HAVE_REMOTE
#include <winsock2.h>
#include "pcap.h"
 
/* prototype of the packet handler */
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);
 
int main()
{
pcap_if_t *alldevs;
pcap_if_t *d;
int inum;
int i=0;
pcap_t *adhandle;
char errbuf[PCAP_ERRBUF_SIZE];
 
    /* Retrieve the device list on the local machine */
    if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
    {
        fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
        exit(1);
    }
 
    /* Print the list */
    for(d=alldevs; d; d=d->next)
    {
        printf("%d. %s", ++i, d->name);
        if (d->description)
            printf(" (%s)\n", d->description);
        else
            printf(" (No description available)\n");
    }
 
    if(i==0)
    {
        printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
        return -1;
    }
}
programming/qt.1623379812.txt.gz · Last modified: 2021/06/11 02:50 by nanodano