So I recently needed to develop some pcap applications on Windows machines. I do development on a variety of platforms (OSX, Linux, and Windows), and I’ve been trying to ’standardize’ on one IDE. Since Eclipse runs on all of those platforms and has support for a variety of programming languages, it seemed like the obvious choice. Here are the steps I followed to get a simple example pcap program to compile.
1) Install Java. Eclipse is written in Java and requires at least the JRE to run. I installed the JDK, because I figured I might be doing Java development on this box at some point. I installed build 1.6.0_20-b02.
2) Install MinGW (Minimalist GNU for Windows). Eclipse provides the development environment, but we still need a compiler to build the code. I installed MinGW-5.1.6 (MinGW has an online, package-based installer like Cygwin).
3) Install Eclipse IDE for C/C++ Developers. This is an installation package with the Eclipse C/C++ Development Tooling (CDT) packages pre-installed. It’s difficult to determine what version I installed, but Help -> About shows Build id: 20100218-1602.
4) Install the WinPcap Driver. I installed version 4.1.1.
5) Install the WinPcap Developer Pack in order to get the header files and libraries. I installed version 4.1.1.
6) Launch Eclipse and create a new Empty Project (File -> New -> C Project and select Empty Project).
7) Add an empty source file (File -> New -> Source File) and paste in the code from the WinPcap Developer Tutorial. We need to make a few alterations. Above the #include "pcap.h" add the following defines:
#define WPCAP
#define HAVE_REMOTE
Then, change main() to int main(int argc, char **argv).
8 ) Now we need to add the include and library directories to the compilation and linking processes, respectively. Click on Project -> Properties -> C/C++ Build -> Settings. Under the ‘GCC C Compiler’ section click on Directories and add the Include directory from WinPcap. Then click on the Libraries item under ‘MinGW C Linker’ and add wpcap under ‘Libraries’ and the Library directory under ‘Library search path’.
9) Cross your fingers and try building the code.