Question

First of all I'm quit new in programming in c/c++, so maybe it's just a basic error but i don't get it. The Problem is, I want to use libpcap in a bigger application, but i can't even integrate the libary into a simple HelloWorld.cpp. Atm I'm using Eclipse (MinGw Compiler) with Windows 64bit, but consindering to switch to Linux if my Problem(s) can't be solved.

Downloaded "libpcap-1.5.3.tar.gz" from tcpdump.org, extracted and added the root directory of the Libary to Eclipse (under "Properties/C|C++ Build" to all Compilers and to the MinGW Linker). My Code:

#include <iostream>
#include <pcap.h>
#include <stdio.h>
using namespace std;

int main(int argc, char *argv[]) {
cout << "Hello World!!!" << endl; // prints Hello World!!!
char *dev = argv[1];

printf("Device: %s\n", dev);
return(0);
}

First error:

D:\Tools\MinGW\lib\libpcap/pcap-stdinc.h:49:22: fatal error: bittypes.h: No such file or directory

So I changed line 49 from

#include "bittypes.h"

to

#include <Win32/Include/bittypes.h>

(the actual location of bittypes.h) and next error pops up:

D:\Tools\MinGW\lib\libpcap/pcap/pcap.h:451:1: error: 'Adapter' does not name a type

'Adapter' is defined in "pcap-int.h" so I included this header into "pcap.h" but now I get:

D:\Tools\MinGW\lib\libpcap/pcap-int.h:46:22: fatal error: Packet32.h: No such file or directory compilation terminated.

and this "Packet32.h" does not exist...

I can't belive this popular libary is broken, so where is my mistake? Thanks in advance!

Was it helpful?

Solution

The Problem is, I want to use libpcap in a bigger application, but i can't even integrate the libary into a simple HelloWorld.cpp. Atm I'm using Eclipse (MinGw Compiler) with Windows

If you want to use libpcap on Windows, you need a version of libpcap that's been ported to Windows. The libpcap source won't build on Windows; on UNIXes, libpcap can and does use packet capture mechanisms built into the OS, but it doesn't do so on Windows (for one thing, older versions of Windows, at least, don't have a packet capture mechanism built in!), so it also needs a driver.

One port of libpcap to Windows is WinPcap; it includes the necessary driver. If you install WinPcap, and then download the WinPcap developer's pack and install it, it should be possible to configure Eclipse so that your program can be built with WinPcap.

OTHER TIPS

libpcap-1.5.3.tar.gz is a source package for the library, not a binary package. So you need to build the library; you can't just add the directory to Eclipse and expect it to work.

The usual way to build a source package is to unpack it into a directory and look for a file called README or INSTALL, which is a simple text file containing instructions on how to build and install the package for various machines. Often there will be multiple such files for different platforms.

Generally, there will be a script called configure that you run to create a Makefile for your target; then you run make to build the code and make install to install it in a standard place so that other packages can find it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top