discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSHost name


From: Richard Frith-Macdonald
Subject: Re: NSHost name
Date: Fri, 18 Apr 2014 21:06:50 +0100

On 18 Apr 2014, at 15:37, Riccardo Mottola <riccardo.mottola@libero.it> wrote:

> Hi,
> 
> Given this situation:
> 
> # hostname
> hobbit
> 
> # hostname -a
> localhost
> 
> 
> I'd expect [[NSHost currentHost] name] to return the name, not the alias.

If you look at the documentation (either the GNUstep documentation or the Apple 
documentation) you will see that your expectation is misguided ... the -name 
method returns *a* name of the host, not necessarily any particular one.

If you have code which prefers particular names, you should use the -names 
method to get all the names for the host, and then use some heuristic to pick 
the one you prefer to use.

Eg, you might want a name without the domain component (so you'd exclude names 
containing dots) and you might want to exclude localhost, and then perhaps you 
might want to pick  the first shortest remaining name in alphabetical order.

All that being said ... I suspect the behavior you are looking for is that of 
the -localizedName method Apple added in OSX 10.6
I've just hacked in a quick implementation (untested) in svn trunk that you 
could try.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]