develooper Front page | perl.perl5.porters | Postings from February 2000

Re: fixing Sys::Hostname

Thread Previous | Thread Next
From:
Andy Dougherty
Date:
February 8, 2000 07:03
Subject:
Re: fixing Sys::Hostname
Message ID:
Pine.SOL.4.10.10002080937060.28432-100000@maxwell.phys.lafayette.edu
On Mon, 7 Feb 2000, Greg Bacon wrote:

> In message <4.3.0.33.0.20000207175053.02576a20@24.8.96.48>,
>     Dan Sugalski writes:
> 
> : It's not a problem for VMS. Five minutes work to get the test in to be 
> : sure--all I need to know is the config.sh name of the symbol. (I presume 
> : d_gethostname, but...)
> 
> d_gethname.  See my patch. :-)

Actually, it's potentially more complicated (but probably not really for
VMS). See the section in config_h.SH starting with:

/* HAS_GETHOSTNAME:
 *      This symbol, if defined, indicates that the C program may use the
 *      gethostname() routine to derive the host name.  See also HAS_UNAME
 *      and PHOSTNAME.
 */
/* HAS_UNAME:
 *      This symbol, if defined, indicates that the C program may use the
 *      uname() routine to derive the host name.  See also HAS_GETHOSTNAME
 *      and PHOSTNAME.
 */
/* PHOSTNAME:
 *      This symbol, if defined, indicates the command to feed to the
 *      popen() routine to derive the host name.  See also HAS_GETHOSTNAME
 *      and HAS_UNAME.  Note that the command uses a fully qualified path,
 *      so that it is safe even if used by a process with super-user
 *      privileges.
 */
/* HAS_PHOSTNAME:
 *      This symbol, if defined, indicates that the C program may use the
 *      contents of PHOSTNAME as a command to feed to the popen() routine
 *      to derive the host name.
 */

The metaconfig unit anticipates the possibility that gethostname() will be
there but inappropriate to use, and allows for other mechanisms to get the
host name.  Probably the most useful one for non-Unix systems is to run
popen($aphostname, "r") to determine the hostname.  aphostname can then be
set to whatever command is appropriate for that platform.  Any Hostname.xs
module ought to honor that fallback if requested.

Oddly enough, when Configure tries to determine the hostname, it doesn't
compile and run a C program to call gethostname.  Unfortunately, that unit
predates my involvement with Configure, so I don't know why. I do know
that older systems didn't necessarily have gethostname() (It's not listed
in my SVR3 manuals, for example), so a fallback was definitely required.
It's also true that some metaconfig units carry a lot of historical
baggage and aren't necessarily optimized for the present day networked
configurations.  The hostname-related ones are probably prime examples of
this.

    Andy Dougherty		doughera@lafayette.edu
    Dept. of Physics
    Lafayette College, Easton PA 18042


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About