Book Image

iOS and OS X Network Programming Cookbook

By : Jon Hoffman
Book Image

iOS and OS X Network Programming Cookbook

By: Jon Hoffman

Overview of this book

Table of Contents (15 chapters)
iOS and OS X Network Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 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: The PCAP_IF_ interface flags. Currently the only possible flag is PCAP_IF_LOOPBACK,...