Retrieving network address information
Most applications that communicate over a network will eventually need to know the information from the available network interfaces of the device they are running on. This recipe will show you how to retrieve the network addresses for all the active network interfaces on the device.
This recipe will use the
NSHost
class to retrieve a list of addresses on your local device. While NSHost
is available on iOS, it is a private (undocumented) class. It is also noted on a number of forum posts that Apple has rejected iOS apps for using NSHost
. If you need to retrieve network address information within an iOS application, it is recommended that you use the Retrieving network address information recipe from Chapter 1, BSD Socket Library, in this book, and not the NSHost
class described in this recipe.
Getting ready
This recipe is compatible with both iOS and OS X, but it is recommended that you do not use NSHost
on the iOS platform. No extra frameworks or libraries...