Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/Foundation.framework |
Availability | Available in Mac OS X v10.0 and later. |
Companion guide | |
Declared in | NSHost.h |
Related sample code |
The NSHost
class provides methods to access the network name and address information for a host. Instances of the NSHost
class represent individual hosts on a network. Use NSHost
objects to get the current host’s name and address and to look up other hosts by name or by address.
To create an NSHost
object, use the currentHost
, hostWithAddress:
, or hostWithName:
class methods (don’t use alloc
and init
). These methods use available network administration services (such as NetInfo or the Domain Name Service) to discover all names and addresses for the host requested. They don’t attempt to contact the host itself, however. This approach avoids untimely delays due to a host being unavailable, but it may result in incomplete information about the host.
An NSHost
object contains all of the network addresses and names discovered for a given host by the network administration services. Each NSHost
object typically contains one unique address, but it may have more than one name. If an NSHost
object has more than one name, the additional names are variations on the same name, typically the basic host name plus the fully qualified domain name. For example, with a host name “sales
” in the domain “anycorp.com
”, an NSHost
object can hold both the names “sales
” and “sales.anycorp.com
”.
The NSHost
class maintains a cache of the NSHost
objects it creates so that requests for an existing NSHost
object return that object instead of creating a new one. Use the setHostCacheEnabled:
method to turn the cache off, forcing lookup of hosts as they’re requested. You can also use the flushHostCache
method to clear the cache of its entries so that subsequent requests look up the host information and create new instances.
Returns an NSHost
object representing the host the process is running on.
+ (NSHost *)currentHost
NSHost
object for the process’s host.
NSHost.h
Releases the cache of existing NSHost
objects so subsequent requests for NSHost
objects create new ones.
+ (void)flushHostCache
NSHost
objects that were retained before this method was invoked remain valid.
NSHost.h
Returns the NSHost
with the Internet address address.
+ (NSHost *)hostWithAddress:(NSString *)address
Network address to look up. For example, @"127.0.0.1"
or @"fe80::1"
.
Host for address.
If caching is turned on and the cache already contains an NSHost
object with address, returns that object. Otherwise, this method creates an instance and returns it.
NSHost.h
Returns a host with a specific name.
+ (NSHost *)hostWithName:(NSString *)hostname
Name of the host to look up. Can be either a simple hostname, such as @"sales"
, or a fully qualified domain name, such as @"sales.anycorp.com"
.
Host named hostname.
If caching is turned on and the cache already contains an NSHost
object with name, returns that object. Otherwise, this method creates a new instance and returns it.
NSHost.h
Indicates whether caching is turned on or off.
+ (BOOL)isHostCacheEnabled
YES
when caching is turned on; NO
otherwise.
NSHost.h
Specifies whether the receiver is to cache instances as it creates them to avoid creating duplicate instances.
+ (void)setHostCacheEnabled:(BOOL)cacheOn
YES
to turn on caching. NO
to turn of caching.
Caching is turned on by default.
This method doesn’t flush the cache. If you turn caching off and then back on, new requests for hosts use what was in the cache at the time caching was turned off. However, NSHost
objects created while caching is turned off aren’t entered into the cache.
NSHost.h
Returns one of the network addresses of the receiver.
- (NSString *)address
One of the network address for the receiver. For example, @"192.42.172.1"
or @"fe80::1"
.
NSHost.h
Returns all the network addresses of the receiver.
- (NSArray *)addresses
All the network addresses of the receiver.
NSHost.h
Indicates whether the receiver represents the same host as another NSHost
object.
- (BOOL)isEqualToHost:(NSHost *)host
Host to compare the receiver to.
YES
when the receiver and host share at least one network address; NO
otherwise.
NSHost.h
Returns one of the hostnames of the receiver.
- (NSString *)name
One of the hostnames of the receiver. Can be either a simple hostname, such as @"sales"
, or a fully qualified domain name, such as @"sales.anycorp.com"
.
NSHost.h
Returns all the hostnames of the receiver.
- (NSArray *)names
All the hostnames of the receiver.
NSHost.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-03-24)