Most applications that use the Internet to communicate will eventually need to convert a hostname to an IP address or an IP address to a hostname. This recipe will encapsulate the network address resolution functionality into a standalone Objective-C class. You will notice in this recipe that most of the CFNetworking API calls are made up of C functions, and use a structure similar to the
addrinfo structure that the BSD API uses.
This recipe is compatible with both iOS and OS X. No extra frameworks or libraries are required.
Let's get started!
The following is the code snippet for creating the
CFNetworkUtilities header file:
#import <Foundation/Foundation.h> ...