This recipe relies on the pcapObject() class from the pcap library to create an instance of sniffer. In the main() method, an instance of this class is created, and a filter is set using the setfilter() method so that only the HTTP packets are captured. Finally, the dispatch() method starts sniffing and sends the sniffed packet to the print_packet() function for postprocessing.
In the print_packet() function, if a packet has data, the payload is extracted using the ip_stack.parse() method from the construct library. This library is useful for low-level data processing.