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 is NULL 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 ...

Get iOS and OS X Network Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.