1 # by David Sundstrom sunds@asictest.sc.ti.com
9 @EXPORT = qw(hostname);
12 # Try every conceivable way to get hostname.
17 # method 1 - we already know it
18 return $host if defined $host;
20 # method 2 - syscall is preferred since it avoids tainting problems
26 $host = "\0" x 65; ## preload scalar
27 syscall(&main::SYS_gethostname, $host, 65) == 0;
30 # method 3 - trusty old hostname command
32 $host = `(hostname) 2>/dev/null`; # bsdish
35 # method 4 - sysV uname command (may truncate)
37 $host = `uname -n 2>/dev/null`; ## sysVish
40 # method 5 - Apollo pre-SR10
42 ($host,$a,$b,$c,$d)=split(/[:\. ]/,`/com/host`,6);
46 || Carp::croak "Cannot get host name of local machine";
49 $host =~ tr/\0\r\n//d;