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

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.