Performing a network address resolution
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.
Getting ready
This recipe is compatible with both iOS and OS X. No extra frameworks or libraries are required.
How to do it…
Let's get started!
Creating the CFNetworkUtilities header file
The following is the code snippet for creating the CFNetworkUtilities
header file:
#import <Foundation/Foundation.h> typedef NS_ENUM(NSUInteger, CFNetworkingSelf.errorCode) { NOERROR, HOSTRESOLUTIONERROR, ADDRESSRESOLUTIONERROR }; @interface CFNetworkUtilities : NSObject @property int (nonatomic) self.errorCode; -(NSArray *)addressesForHostname...