Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: $HOST on OS X

On Sat, 5 Jun 2010, William G. Scott wrote:

> Dear citizens:
> I just noticed odd behavior for how $HOST is getting set on OS X v. 
> 10.6.3.
> One one home machine connected to a wireless router and ADSL modem:
> % print $HOST
> internalcheck.apple.com
> On another -- This one worries me more:
> % print $HOST
> e3191.c.akamaiedge.net
> The manual says $HOST is automatically set by the shell, but I wonder 
> how this is happening?  I don't have anything weird in /etc/hosts for 
> example...

$HOST is set by the following lines in Src/params.c:

682    hostnam = (char *)zalloc(256);
683    gethostname(hostnam, 256);
684    setsparam("HOST", ztrdup(hostnam));

If gethostname is defined in unistd.h, it's a standard library call that 
fills its char* first parameter with your hostname.  Otherwise, there's 
a compatibility replacement in Src/compat.c that basically gets the node 
name via uname.  Omitting error-checking, it's:

int gethostname(char*name, size_t namelen) {
    struct utsname uts;

So, either way, it follows a pretty standard path to getting a hostname.

I'm not sure whether OS X would have gethostname, but what does `uname 
-n` return?  Or `hostname`?


Messages sorted by: Reverse Date, Date, Thread, Author