Retrieving network device information
When we start using libpcap, we can specify a particular interface or let libpcap pick one up for us. In this recipe, we will retrieve a list of the network interfaces that are available and the address information for those interfaces.
To retrieve all of the devices, we use the
pcap_findalldevs()
function that returns a linked list of network interfaces. Each element in the list is of the pcap_if_t
type. The
pcap_if_t
structure contains the following elements:
pcap_if *next
: This denotes the next element in the list. The value isNULL
if it is the last element.char *name
: This denotes the name of the device. This name can be passed to other functions to identify the device.char *description
: This description provides a human-readable description of the device.pcap_addr *addresses
: This is a pointer to the first element of a list of addresses for the interface.u_int
: ThePCAP_IF_
interface flags. Currently the only possible flag isPCAP_IF_LOOPBACK
,...