Simple examples for programmers


The following are two basic example that show how to write a program that captures packet from the network using the NDIS packet capture driver. The first uses the driver's functions through the packet.dll; the second performs the capture using the functions provided by libpcap. Note that the two programs are very similar in the behavior and the output not too different, but the code of  the version that uses libpcap is shorter and simpler.

Example using the Packet Driver

A very simple capture program is provided to show the use of the packet capture driver and of 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.

Example using libpcap

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, and was compiled in Windows without being modified. It can run, once compiled, in Windows 95 and Windows NT.