NSHost Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in OS X v10.0 and later. |
| Companion guide | Interacting with the Operating System |
| Declared in | NSHost.h |
Overview
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.
Tasks
Creating Hosts
Getting Host Information
Comparing Hosts
Managing the Host Cache
-
+ flushHostCacheDeprecated in OS X v10.7 -
+ isHostCacheEnabledDeprecated in OS X v10.7 -
+ setHostCacheEnabled:Deprecated in OS X v10.7
Class Methods
currentHost
Returns an NSHost object representing the host the process is running on.
Return Value
NSHost object for the process’s host.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSHost.hhostWithAddress:
Returns the NSHost with the Internet address address.
Parameters
- address
Network address to look up. For example,
@"127.0.0.1"or@"fe80::1".
Return Value
The host for address.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSHost.hhostWithName:
Returns a host with a specific name.
Parameters
- 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".
Return Value
The host named hostname.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSHost.hInstance Methods
address
Returns one of the network addresses of the receiver.
Return Value
One of the network address for the receiver. For example, @"192.42.172.1" or @"fe80::1".
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSHost.haddresses
Returns all the network addresses of the receiver.
Return Value
All the network addresses of the receiver.
Availability
- Available in OS X v10.0 and later.
Declared In
NSHost.hisEqualToHost:
Indicates whether the receiver represents the same host as another NSHost object.
Parameters
- host
Host to compare the receiver to.
Return Value
YES when the receiver and host share at least one network address; NO otherwise.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSHost.hlocalizedName
Returns the name used as by default when publishing NSNetServices.
Return Value
A string containing the computer name.
Discussion
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.
Availability
- Available in OS X v10.6 and later.
Declared In
NSHost.hname
Returns one of the hostnames of the receiver.
Return Value
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".
Availability
- Available in OS X v10.0 and later.
Declared In
NSHost.hnames
Returns all the hostnames of the receiver.
Return Value
All the hostnames of the receiver.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSHost.h© 2010 Apple Inc. All Rights Reserved. (Last updated: 2010-04-28)