WinPcap with Dev C++

This is a discussion on WinPcap with Dev C++ within the C++ Programming forums, part of the General Programming Boards category; Hey so I have been trying to get the WinPcap libraries to work with Dev C++ for the last couple ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    6

    WinPcap with Dev C++

    Hey so I have been trying to get the WinPcap libraries to work with Dev C++ for the last couple days and have had no luck. It seems everyone else is having the same problems as I checked the internet and all I seem to find is reports of this problems but no solutions. So I will try to make this as understandable as possible. I installed the appropriate drivers for the libraries. I have saved the contents of the WinPcap libraries into Dev C++'s lib folder. I saved the required includes (.h files) into the the include folder in the Dev C++ directory. I then made some changes to one of the C examples provided, and created a new C++ project. I linked to wpcap.lib and libws2_32.a and then compiled it. Here is the code and error I got.

    Code:
    #include <pcap.h>
    
    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(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
        {
            cout << "Error in pcap_findalldevs_ex: %s\n";
            return 0;
        }
        
        /* 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");
            return 0;
        }
    
        /* We don't need any more the device list. Free it */
        pcap_freealldevs(alldevs);
    
        return 0;
    }
    Code:
    Compiler: Default compiler
    Building Makefile: "C:\Users\Scott\Documents\c++ workspace\scoket workspace\syn test v1\Makefile.win"
    Executing  make...
    make.exe -f "C:\Users\Scott\Documents\c++ workspace\scoket workspace\syn test v1\Makefile.win" all
    g++.exe -c main.cpp -o main.o -I"C:/Program_Files/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Program_Files/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Program_Files/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Program_Files/Dev-Cpp/include/c++/3.4.2"  -I"C:/Program_Files/Dev-Cpp/include"   
    
    main.cpp: In function `int main()':
    main.cpp:11: error: `PCAP_SRC_IF_STRING' undeclared (first use this function)
    main.cpp:11: error: (Each undeclared identifier is reported only once for each function it appears in.)
    main.cpp:11: error: `pcap_findalldevs_ex' undeclared (first use this function)
    main.cpp:13: error: `cout' undeclared (first use this function)
    
    make.exe: *** [main.o] Error 1
    
    Execution terminated
    For some reason it isn't registering that certain functions are in the library. I also linked to libwpcap.a just to be sure but nothing changed. Also I know there are other errors in the code I.E. me not defining any standard libraries but this is just to illustrate a point and get the problem fixed im actually just using these select functions in a much bigger project and just posted this as a quick demo. Any thoughts?
    Last edited by ScottyK; 11-09-2010 at 10:47 PM.

  2. #2
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    681
    Don't copy any library files to include/lib directories, instead, add search directories.
    Dev C++ is no longer supported, and the MinGW version that is shipped with this IDE is old and outdated. The best choice for MinGW is CodeBlocks IMO.

    I had a look at my old WinPcap project, and noticed that there is a #define preceding the inclusion of <pcap.h>:

    #include <winsock2.h>
    #include <ws2tcpip.h>
    #include <windows.h>

    #pragma option push -pc
    #define HAVE_REMOTE
    #include <pcap.h>
    #pragma option pop

    Add #define HAVE_REMOTE before <pcap.h> and check if it works. The example you provided is broken or incomplete, cout is in std:: namespace.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    Yes I appoligze for the poor example I quickly ported something from C and did a terrible job. Anyways thank you for providing that information, would it save me a lot of time and effort if I just used visual studios 2010 C++ compiler instead? I am a student and have a pfree MSDN license are the libraries supported by Visual C++?

  4. #4
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    681
    Yes they are supported. It all depends what you want to write and whether you pay attention to portability.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    Hey so I finally got around to downloading Visual Studios 2010 just a couple questions on using it with the WinPcap libraries. What are the default directories in which I need to place the WinPcap .lib and .h files and what exactly do I need to add as additional dependencies?
    Last edited by ScottyK; 11-23-2010 at 09:10 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Whats better, C-Free or Dev C++??
    By i_can_do_this in forum Tech Board
    Replies: 10
    Last Post: 07-07-2006, 04:34 AM
  2. New to Dev C++/<windows.h>...
    By Cilius in forum C++ Programming
    Replies: 3
    Last Post: 02-23-2005, 12:05 AM
  3. Glut and Dev C++, Programs not Quitting?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-29-2004, 07:43 PM
  4. openGL programming - From MSVC++ to Dev C++
    By WDT in forum Game Programming
    Replies: 1
    Last Post: 03-08-2004, 04:19 PM
  5. DEV C++ Limitations?
    By Kirdra in forum Game Programming
    Replies: 3
    Last Post: 09-09-2002, 09:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21