## Introduction

This Manual describes the programming interface and the source code of WinPcap. It provides detailed descriptions of the functions and structures exported to programmers, along with complete documentation of the WinPcap internals. Several tutorials and examples are provided as well.

You can follow the links at the top of this page or use the tree control at the left to reach sections of interest.

This documentation was created using the Doxygen documentation system, that can be found at http://www.doxygen.org.

## What is WinPcap

WinPcap is an open source library for packet capture and network analysis for the Win32 platforms.

Most networking applications access the network through widely used operating system primitives such as sockets. It is easy to access data on the network with this approach since the operating system copes with the low level details (protocol handling, packet reassembly, etc.) and provides a familiar interface that is similar to the one used to read and write files.

Sometimes, however, the 'easy way' is not up to the task, since some applications require direct access to packets on the network. That is, they need access to the "raw" data on the network without the interposition of protocol processing by the operating system.

The purpose of WinPcap is to give this kind of access to Win32 applications; it provides facilities to:

- capture raw packets, both the ones destined to the machine where it's running and the ones exchanged by other hosts (on shared media)
- filter the packets according to user-specified rules before dispatching them to the application
- transmit raw packets to the network
- gather statistical information on the network traffic

This set of capabilities is obtained by means of a device driver, that is installed inside the networking portion of Win32 kernels, plus a couple of DLLs.

All these features are exported through a powerful programming interface, easily exploitable by the applications and available on different OSes. The main goal of this manual is to document this interface, with the help of several examples. If you are interested in starting your exploration right away you can go directly to the WinPcap user's manual.

### What kind of programs use WinPcap

The WinPcap programming interface can be used by many types of network tools for analysis, troubleshooting, security and monitoring. In particular, classical tools that rely on WinPcap are:

- network and protocol analyzers
- network monitors
- traffic loggers
- traffic generators
- user-level bridges and routers
- network intrusion detection systems (NIDS)
- network scanners
- security tools

### What WinPcap can't do

WinPcap receives and sends the packets independently from the host protocols, like TCP-IP. This means that it isn't able to block, filter or manipulate the traffic generated by other programs on the same machine: it simply "sniffs" the packets that transit on the wire. Therefore, it does not provide the appropriate support for applications like traffic shapers, QoS schedulers and personal firewalls.

## Purpose of this manual

The purpose of this manual is to provide a comprehensive and easy way to browse the documentation of the WinPcap architecture. You will find two main sections: \ref wpcap and \ref internals.

The first one can be used by a programmer who needs to exploit WinPcap from an application: it contains all the information about functions and data structures exported by the WinPcap API, a manual that explains how to write packet filters and a page that explains how to include it in an application. A tutorial with several code samples is provided as well; it can be used to learn the basics of the WinPcap API using a step-by-step approach, but it also offers code snippets that demonstrate advanced features.

The second section is intended for WinPcap developers and maintainers, or for people who are curious about how this system works: it provides a general description of the WinPcap architecture and explains how it works. Additionally, it documents the complete device driver structure, the source code, the packet.dll interface and the low-level WinPcap API. If you want to understand what happens inside WinPcap or if you need to extend it, this is the section you will want to read. \htmlonly

## Additional Documentation

For additional and up-to-date documentation, we suggest that you look at http://www.winpcap.org/docs/

In particular, if you are interested in the structure and the internals of WinPcap, we suggest reading the following documents:

- Fulvio Risso, Loris Degioanni, An Architecture for High Performance Network Analysis, Proceedings of the 6th IEEE Symposium on Computers and Communications (ISCC 2001), Hammamet, Tunisia, July 2001
- Loris Degioanni, Mario Baldi, Fulvio Risso and Gianluca Varenni, Profiling and Optimization of Software-Based Network-Analysis Applications, Proceedings of the 15th IEEE Symposium on Computer Architecture and High Performance Computing (SBAC-PAD 2003), Sao Paulo, Brasil, November 2003
- Loris Degioanni, Development of an Architecture for Packet Capture and Network Traffic Analysis, Graduation Thesis, Politecnico Di Torino (Turin, Italy, Mar. 2000)

## Terminology

- For consistency with the literature, we will use the term packet even though frame is more accurate since the capture process is done at the data-link layer and the data-link header is included in the captured data.
- The term Win9x will be used in this documentation to indicate the family of Microsoft OSes made up of Windows 95 and its derivatives, i.e. Windows 98 and Windows ME. The term WinNTx will indicate the OSes built upon the NT kernel, starting from Windows NT 4 and including Windows 2000, Windows XP, Windows Server 2003 and so on.

## Note

Our development and documentation efforts focus primarily on the Windows NT/2000/XP/2003 version of WinPcap. This choice is based on the fact that the majority of the WinPcap users work on NTx systems, but also because the 9x technology has been abandoned by Microsoft. Moreover, we assume that a person who needs to use a PC for an advanced task like network analysis will install an advanced OS on the machine. For this reason, the documentation will refer to the WinNTx drivers and APIs. Win9x versions are very similar in the concept but sometimes differ in the implementation and, occasionally, the Win9x version of the API lacks some of the more advanced functionality. This manual describes the complete API and will indicate when a function is present only in Windows NTx.