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 |
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
”.
NSHost
methods are thread-safe.
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
does not implement caching in Mac OS X v10.6 and later.
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"
.
The host for address.
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"
.
The host named hostname.
NSHost.h
Indicates whether caching is turned on or off.
+ (BOOL)isHostCacheEnabled
YES
when caching is turned on; NO
otherwise.
NSHost
does not implement caching in Mac OS X v10.6 and later.
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.
NSHost
does not implement caching in Mac OS X v10.6 and later.
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 the name used as by default when publishing NSNetServices
.
- (NSString *)localizedName
A string containing the computer name.
This is the name displayed in the Finder sidebar, as well as in the Sharing preference panel.
This method only returns an NSString
when sent to the the currentHost
instance, all other instances currently return nil
.
This property is key-value observable.
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
Last updated: 2010-04-28