The creation of an application that uses the capture driver through packet.dll is quite trivial. The following things must be done in order to compile the application:
The application, doing so, will be able to use the functions exported by the DLL and to use the driver to capture packets.
The following things must be done to compile an application that uses libpcap:
The application, doing so, will be able to use the functions exported by libpcap and use the NDIS packet capture driver to capture packets.
Remember that:
Note: when compiling a program using libpcap it is not necessary to include the packet32.h and packet.lib files to interact with packet.dll, because libpcap.lib includes also the code present in packet.lib. The pcap library, in fact, uses the packet.dll API, but hides it to the programmer, giving a higher level of abstraction and a more powerful interface.
Assuming that you are able to compile the application in Windows (this operation can be very difficult and is cannot be explained here), the only thing you have to do is to link it with libpcap for Windows, following the steps of the previous Section.
The following things must be done to compile an application that uses libpcap:
The application, doing so, will be able to use the functions exported by libpcap and to use the NDIS packet capture driver to capture packets. Note that it is not necessary to include the packet32.h and packet.lib files to interact with packet.dll, because the code present in packet.lib is already present in libpcap.lib.
The following are examples that show how to write programs that capture packets from the network using the NDIS packet capture driver. The first uses the driver's functions through packet.dll. The second performs a capture using the functions provided by libpcap. The third is a more complex program, that uses libpcap from C++. All the examples, once compiled, can run both on Windows 95 and on Windows NT. The source code of the examples, along with all the files needed to compile and run them, can be found in the Developer's Pack.
This is a very simple capture program that shows the use of the packet capture driver through the PACKET.DLL API. It is a console application that can work in Windows 95 and Windows NT. It captures the packets from the network adapter specified by the user until a key is pressed, dumping the content of each packet on the screen.
This example shows how to write and compile an application that uses the packet capture library under the Win32 environment. This example reads the packets from a file or a network adapter, printing on the screen the timestamp, the length and the data of the packets. It was originally written for UNIX (the UNIX makefile is provided), and was compiled in Windows without being modified. It can run, once compiled, in Windows 95 and Windows NT. Notice that this program is very similar to the previous in the behavior and the output is not too different, but the code of the version that uses libpcap is shorter and simpler.
This program shows an alternative and light-weight use of libpcap. NetMeter draws in a window the scrolling diagram of the network's load. The network's load is calculated counting the number of bytes transmitted by the network every second. The application is written in C++ with MFC, and uses libpcap to capture from the network.