xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/hostname.pl (revision 0:68f95e015346)
1*0Sstevel@tonic-gate# From: asherman@fmrco.com (Aaron Sherman)
2*0Sstevel@tonic-gate#
3*0Sstevel@tonic-gate# This library is no longer being maintained, and is included for backward
4*0Sstevel@tonic-gate# compatibility with Perl 4 programs which may require it.
5*0Sstevel@tonic-gate#
6*0Sstevel@tonic-gate# In particular, this should not be used as an example of modern Perl
7*0Sstevel@tonic-gate# programming techniques.
8*0Sstevel@tonic-gate#
9*0Sstevel@tonic-gate# Suggested alternative: Sys::Hostname
10*0Sstevel@tonic-gate#
11*0Sstevel@tonic-gatesub hostname
12*0Sstevel@tonic-gate{
13*0Sstevel@tonic-gate	local(*P,@tmp,$hostname,$_);
14*0Sstevel@tonic-gate	if (open(P,"hostname 2>&1 |") && (@tmp = <P>) && close(P))
15*0Sstevel@tonic-gate	{
16*0Sstevel@tonic-gate		chop($hostname = $tmp[$#tmp]);
17*0Sstevel@tonic-gate	}
18*0Sstevel@tonic-gate	elsif (open(P,"uname -n 2>&1 |") && (@tmp = <P>) && close(P))
19*0Sstevel@tonic-gate	{
20*0Sstevel@tonic-gate		chop($hostname = $tmp[$#tmp]);
21*0Sstevel@tonic-gate	}
22*0Sstevel@tonic-gate	else
23*0Sstevel@tonic-gate	{
24*0Sstevel@tonic-gate		die "$0: Cannot get hostname from 'hostname' or 'uname -n'\n";
25*0Sstevel@tonic-gate	}
26*0Sstevel@tonic-gate	@tmp = ();
27*0Sstevel@tonic-gate	close P; # Just in case we failed in an odd spot....
28*0Sstevel@tonic-gate	$hostname;
29*0Sstevel@tonic-gate}
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate1;
32