Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Winpcap help

Winpcap help

Scheduled Pinned Locked Moved Solved Qt 6
5 Posts 2 Posters 632 Views
  • 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.
  • P Offline
    P Offline
    Pordo
    wrote on 15 Aug 2022, 18:37 last edited by
    #1

    Hello! I'm using version 6.3 of Qt Creator and I'm trying to use winpcacp version 4.1.2 library (I'm download from here https://www.winpcap.org/devel.htm). I am trying to run the first example code of the winpacp manual but I get the following errors and I do not know how to fix it:

    :-1: error: debug/main.o:C:\Users\lucas\Desktop\build-prueba2-Desktop_Qt_6_3_1_MinGW_64_bit-Debug/../prueba2/main.cpp:22: undefined reference to `pcap_findalldevs_ex'

    :-1: error: debug/main.o: in function `main':

    C:\Users\lucas\Desktop\prueba2\main.cpp:44: error: undefined reference to `pcap_freealldevs'

    :-1: error: collect2.exe: error: ld returned 1 exit status

    :-1: error: [Makefile.Debug:68: debug/prueba2.exe] Error 1

    Here is the code:
    In .pro file I have:
    QT -= gui

    CONFIG += c++17 console
    CONFIG -= app_bundle

    SOURCES +=
    main.cpp

    //# Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target

    INCLUDEPATH += C:/Users/lucas/Desktop/prueba2/WpdPack/Include
    LIBS += "-LC:/Users/lucas/Desktop/prueba2/WpdPack/Lib/x64"

    DEFINES += WPCAP
    DEFINES += HAVE_REMOTE

    And in main.cpp I have:
    #include <stdlib.h>
    #include <stdio.h>
    #include <pcap.h>

    using namespace std;

    int main()
    {
    pcap_if_t *alldevs;
    pcap_if_t *d;
    int i=0;
    char errbuf[PCAP_ERRBUF_SIZE];

    /* Retrieve the device list from the local machine */
    if (pcap_findalldevs_ex((char*)PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1)
    {
        fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);
        exit(1);
    }
    
    /* Print the list */
    for(d= alldevs; d != NULL; 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");
    }
    
    /* We don't need any more the device list. Free it */
    pcap_freealldevs(alldevs);
    return 0;
    

    }

    J 1 Reply Last reply 15 Aug 2022, 18:55
    0
    • P Pordo
      15 Aug 2022, 19:24

      sorry it's the first time I've used a forum, as it was a different code from an example that I saw I thought I had to open another post.

      from the other post, today I try to put the path I put in this new code and Qt stop giving problems when compiling the #include<pcap.h>
      the problem was that I was putting ...WpdPack/Lib and it was ...WpdPack/Lib/x64

      After that, I try to use the example from the manual and now I have this new problem. For your question Where exactly do you actually link with whatever "pcap" library, because I do not see anything? I don't know where I can check that

      I see in another pages that the Winpcap have to linker but I dont know how to make that. I thought that with the INCLUDEPATH and LIBS I make this linker but I'm not sure

      J Offline
      J Offline
      JonB
      wrote on 15 Aug 2022, 19:41 last edited by
      #4

      @Pordo
      Your line

      LIBS += "-LC:/Users/lucas/Desktop/prueba2/WpdPack/Lib/x64"
      

      tells the linker where to look for libraries. That's good. But you also have to tell it what library there you want it to link with. Something like

      LIBS += "-LC:/Users/lucas/Desktop/prueba2/WpdPack/Lib/x64" -lpcap
      

      See what I've added at the end? I thought you had something like this in your other post? Your instructions must tell you this, I don't know what the library is actually called.

      1 Reply Last reply
      1
      • P Pordo
        15 Aug 2022, 18:37

        Hello! I'm using version 6.3 of Qt Creator and I'm trying to use winpcacp version 4.1.2 library (I'm download from here https://www.winpcap.org/devel.htm). I am trying to run the first example code of the winpacp manual but I get the following errors and I do not know how to fix it:

        :-1: error: debug/main.o:C:\Users\lucas\Desktop\build-prueba2-Desktop_Qt_6_3_1_MinGW_64_bit-Debug/../prueba2/main.cpp:22: undefined reference to `pcap_findalldevs_ex'

        :-1: error: debug/main.o: in function `main':

        C:\Users\lucas\Desktop\prueba2\main.cpp:44: error: undefined reference to `pcap_freealldevs'

        :-1: error: collect2.exe: error: ld returned 1 exit status

        :-1: error: [Makefile.Debug:68: debug/prueba2.exe] Error 1

        Here is the code:
        In .pro file I have:
        QT -= gui

        CONFIG += c++17 console
        CONFIG -= app_bundle

        SOURCES +=
        main.cpp

        //# Default rules for deployment.
        qnx: target.path = /tmp/$${TARGET}/bin
        else: unix:!android: target.path = /opt/$${TARGET}/bin
        !isEmpty(target.path): INSTALLS += target

        INCLUDEPATH += C:/Users/lucas/Desktop/prueba2/WpdPack/Include
        LIBS += "-LC:/Users/lucas/Desktop/prueba2/WpdPack/Lib/x64"

        DEFINES += WPCAP
        DEFINES += HAVE_REMOTE

        And in main.cpp I have:
        #include <stdlib.h>
        #include <stdio.h>
        #include <pcap.h>

        using namespace std;

        int main()
        {
        pcap_if_t *alldevs;
        pcap_if_t *d;
        int i=0;
        char errbuf[PCAP_ERRBUF_SIZE];

        /* Retrieve the device list from the local machine */
        if (pcap_findalldevs_ex((char*)PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1)
        {
            fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);
            exit(1);
        }
        
        /* Print the list */
        for(d= alldevs; d != NULL; 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");
        }
        
        /* We don't need any more the device list. Free it */
        pcap_freealldevs(alldevs);
        return 0;
        

        }

        J Offline
        J Offline
        JonB
        wrote on 15 Aug 2022, 18:55 last edited by
        #2

        @Pordo
        I seem to have tried to help you in your other post(s) about this issue, to no avail. You now open a new one.

        Your error is a linker error. Where exactly do you actually link with whatever "pcap" library, because I do not see anything?

        1 Reply Last reply
        1
        • P Offline
          P Offline
          Pordo
          wrote on 15 Aug 2022, 19:24 last edited by
          #3

          sorry it's the first time I've used a forum, as it was a different code from an example that I saw I thought I had to open another post.

          from the other post, today I try to put the path I put in this new code and Qt stop giving problems when compiling the #include<pcap.h>
          the problem was that I was putting ...WpdPack/Lib and it was ...WpdPack/Lib/x64

          After that, I try to use the example from the manual and now I have this new problem. For your question Where exactly do you actually link with whatever "pcap" library, because I do not see anything? I don't know where I can check that

          I see in another pages that the Winpcap have to linker but I dont know how to make that. I thought that with the INCLUDEPATH and LIBS I make this linker but I'm not sure

          J 1 Reply Last reply 15 Aug 2022, 19:41
          0
          • P Pordo
            15 Aug 2022, 19:24

            sorry it's the first time I've used a forum, as it was a different code from an example that I saw I thought I had to open another post.

            from the other post, today I try to put the path I put in this new code and Qt stop giving problems when compiling the #include<pcap.h>
            the problem was that I was putting ...WpdPack/Lib and it was ...WpdPack/Lib/x64

            After that, I try to use the example from the manual and now I have this new problem. For your question Where exactly do you actually link with whatever "pcap" library, because I do not see anything? I don't know where I can check that

            I see in another pages that the Winpcap have to linker but I dont know how to make that. I thought that with the INCLUDEPATH and LIBS I make this linker but I'm not sure

            J Offline
            J Offline
            JonB
            wrote on 15 Aug 2022, 19:41 last edited by
            #4

            @Pordo
            Your line

            LIBS += "-LC:/Users/lucas/Desktop/prueba2/WpdPack/Lib/x64"
            

            tells the linker where to look for libraries. That's good. But you also have to tell it what library there you want it to link with. Something like

            LIBS += "-LC:/Users/lucas/Desktop/prueba2/WpdPack/Lib/x64" -lpcap
            

            See what I've added at the end? I thought you had something like this in your other post? Your instructions must tell you this, I don't know what the library is actually called.

            1 Reply Last reply
            1
            • P Offline
              P Offline
              Pordo
              wrote on 15 Aug 2022, 19:55 last edited by
              #5

              Thanks a lot! now I understand well why it was that of L and l. Try that and it works!

              1 Reply Last reply
              0

              2/5

              15 Aug 2022, 18:55

              • Login

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