In this recipe, we will show you how to use the libpcap library to capture packets. We will also introduce some basic libpcap concepts, such as the
pcap handler and filters.
Prior to running this recipe, we need to follow the Adding libpcap to your project recipe presented earlier in this chapter.
Let's capture some packets by following the ensuing steps:
#define SNAPLEN 65535 #define PROMISC 1 #define TIMEOUT 500
SNAPLEN constant defines the maximum size of the packet to be captured. The
PROMISC constant specifies whether we want to set the interface to the promiscuous mode or not;
1 is true and
0 is false. The
TIMEOUT constant ...