O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hosts

NSHost provides services that find host names from addresses and addresses from host names. NSHost relies on the network services available to the operating system, such as LDAP, NetInfo, or the Domain Name Service (DNS). Example 6-1 shows how to use NSHost.

Example 6-1. Using NSHost
                  // Get the NSHost object for the current host
NSHost *host = [NSHost currentHost];

// Get the name of a host
NSString *name = [host name];

// Get the address of a host; returns "xxx.xxx.xxx.xxx" string
NSString *addr = [host address];

// Other ways to create a host object
NSHost *host = [NSHost hostWithAddress:@"www.oreilly.com"];
NSHost *host = [NSHost hostWithName:@"209.204.146.22"];

// If a host has multiple names or address, use the following
NSArray *names = [host names];
NSArray *addrs = [host addresses];

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required