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

Re: [MacPerl] How to get the TCP/IP host name



At 3:09 PM +0200 3/30/99, Milivoj Ivkovic wrote:

} >>gethostbyname('localhost'); # OK on Win32, not Linux
} >
} >Works on a Mac, at least in part, assuming you know what to expect from the
} >return value.  In a scalar context, returns the IP address as a packed 4
} >character string.
}
} Used it in array context on Win32, and it gives the full host name in
}first element. What does it give in array context on a Mac? (On Linux, it
}just stupidly gives 'localhost.localdomain')

Probably because that's what's in /etc/hosts or in one of the startup files
(there's a place where you tell it the hostname upon boot, and I believe
it's set to 'localhost.localdomain' by default).  I'll bet it differs from
machine to machine.  Whether the machine is doing DNS locally probably also
factors in.

On my Mac, MacPerl gives back the fqdn.  I don't know whether Open
Transport (MacOS TCP/IP software) or my provider's DNS gets the credit.

}
} >I thought this might be used with gethostbyaddr to get the host name as
} >well, but I was unable to get that to work in under 5 minutes.
}
} As I understand it, this uses reverse lookup, which is not always
}configured. So I wouldn't expect it to be reliable.
}
} >>`hostname` # OK on Linux, not Win32
} >
} >Works in a Mac.
} >
}
} Really? Sounds great. On any Mac (with Perl)? Or just on some Macs which
}have installed some additional Unix tools or such?

The interpretation of `hostname` is built into MacPerl itself.  Works on
any Mac with MacPer.

}
} >>$ENV{'HOSTNAME'} # OK on Linux, not Win32
} >
} >Doesn't work on a Mac in the sense of giving you the hostname, but that's
} >sort of expected.  It is my understanding that this is not guaranteed to
} >work on a *nix system either.
}
} Yes, I was considering this as a last resort only, once everything else
}has failed.

You might also look into Net::Domain (part of libnet), although I don't
know how well it works on Win32 and I just sent a patch for MacOS, because
there are problems.  But it should work on Unix, and it tries many methods
to get the answer.  You can't rely on it being installed everywhere,
though, although it comes with MacPerl.

}
} Thank you for your help.
}



-----
Paul J. Schinder
schinder@pobox.com

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org