Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to add win10pcap to QT proj
Forum Updated to NodeBB v4.3 + New Features

How to add win10pcap to QT proj

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • John_QtJ Offline
    John_QtJ Offline
    John_Qt
    wrote on last edited by
    #1

    Hi all,
    I am using Qt Creator 4.3.1 on Windows 10. I would like to use Win10pcap library on Qt but I don't know how to include and use it on Qt. Is there anyone here know about it? Thank in advance.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      http://doc.qt.io/qtcreator/creator-project-qmake-libraries.html
      http://doc.qt.io/qt-5/third-party-libraries.html

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • John_QtJ Offline
        John_QtJ Offline
        John_Qt
        wrote on last edited by
        #3

        @VRonin
        I have download Win10pcap from http://www.win10pcap.org/download/ . And then installed it on my desktop, but I can find the way to include it on Qt.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          What did you try ? What did not work ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • John_QtJ Offline
            John_QtJ Offline
            John_Qt
            wrote on last edited by
            #5

            Hi @SGaist,
            I did download http://www.win10pcap.org/download/ for win10pcap installer. And installed it on desktop. After that, I download https://www.winpcap.org/devel.htm for Winpcap developer pack as mentioned in Win10pcap website.
            After download, I include wpcap.dll and Packet.dll in .pro file as below:
            "
            INCLUDEPATH += C:/mypath/WpdPack/Include
            LIBS += -L C:/mypath/WpdPack/Lib -lwpcap -lPacket
            "

            And then try the code from winpcap website with the change :
            #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( &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;
            }
            
            printf("Enter the interface number (1-%d):",i);
            scanf("%d", &inum);
            
            if(inum < 1 || inum > i)
            {
                printf("\nInterface number out of range.\n");
                /* Free the device list */
                pcap_freealldevs(alldevs);
                return -1;
            }
            
            /* Jump to the selected adapter */
            for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
            
            /* Open the device */
            if ( (adhandle= pcap_open_live(d->name,          // name of the device
                                      65536,            // portion of the packet to capture
                                                        // 65536 guarantees that the whole packet will be captured on all the link layers
                                      1,              //PCAP_OPENFLAG_PROMISCUOUS,    // promiscuous mode
                                      1000,             // read timeout
                                      NULL             // authentication on the remote machine
                                                              //errbuf            // error buffer
                                      ) ) == NULL)
            {
                fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", d->name);
                /* Free the device list */
                pcap_freealldevs(alldevs);
                return -1;
            }
            
            printf("\nlistening on %s...\n", d->description);
            
            /* At this point, we don't need any more the device list. Free it */
            pcap_freealldevs(alldevs);
            
            /* start the capture */
            pcap_loop(adhandle, 0, packet_handler, NULL);
            
            return 0;
            

            }

            /* Callback function invoked by libpcap for every incoming packet */
            void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data)
            {
            struct tm ltime;
            char timestr[16];
            time_t local_tv_sec;

            /*
             * unused variables
             */
            (VOID)(param);
            (VOID)(pkt_data);
            
            /* convert the timestamp to readable format */
            local_tv_sec = header->ts.tv_sec;
            localtime_s(&ltime, &local_tv_sec);
            strftime( timestr, sizeof timestr, "%H:%M:%S", &ltime);
            
            printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);
            

            }

            But the code compile fine, but it doesn't run anything. I don't know what wrong with my win10pcap setup or the code.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Go to the Run part of the Project panel, there edit the PATH environment variable and add the path to were the Win10Pcap .dll files can be found.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              John_QtJ 2 Replies Last reply
              0
              • SGaistS SGaist

                Go to the Run part of the Project panel, there edit the PATH environment variable and add the path to were the Win10Pcap .dll files can be found.

                John_QtJ Offline
                John_QtJ Offline
                John_Qt
                wrote on last edited by
                #7

                @SGaist
                I tried. It doesn't work.

                1 Reply Last reply
                0
                • SGaistS SGaist

                  Go to the Run part of the Project panel, there edit the PATH environment variable and add the path to were the Win10Pcap .dll files can be found.

                  John_QtJ Offline
                  John_QtJ Offline
                  John_Qt
                  wrote on last edited by
                  #8

                  @SGaist
                  The application was able to start correctly (0x000007b). Click ok to close the program.

                  1 Reply Last reply
                  0
                  • hskoglundH Offline
                    hskoglundH Offline
                    hskoglund
                    wrote on last edited by
                    #9

                    Hi, I'm guessing the error 0xc000007b means, you've set the PATH ok to the pcap dll, but it has the wrong bitness, either it's 64-bit and your Qt program is built in 32-bit mode or the other way around.

                    1 Reply Last reply
                    3

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved