Path: utzoo!attcan!uunet!cs.utexas.edu!mailrus!uflorida!usfvax2!tct!chip From: chip@tct.uucp (Chip Salzenberg) Newsgroups: comp.lang.perl Subject: Re: gethostname() in perl Message-ID: <25D02290.62B4@tct.uucp> Date: 7 Feb 90 13:28:48 GMT References: <1018@frankland-river.aaii.oz.au> Organization: ComDev/TCT, Sarasota, FL Lines: 43 According to pem@frankland-river.aaii.oz.au (Paul E. Maisano): >This is how I find the hostname of the machine I am running on. > > do 'syscall.pl' || die "syscall.pl: $@\n"; > > $host = "\0" x 100; # pre-nulled buffer for hostname > syscall($SYS_GETHOSTNAME, $host, length($host)); > >syscall.pl is just of file of system call numbers. A comparable method could be used under SysV, with $SYS_UNAME. Unfortunately, a portable definition of "struct utsname" is not possible -- every vendor does it differently. Sigh. It's worth noting that Xenix systems have uname(), but the "real" (UUCP) hostname is actually in a file: /etc/systemid. So the Perl version of gethostname() for Xenix looks like: sub gethostname() { local(*id); return "unknown" unless open(id, "/etc/systemid"); $id = ; close(id); chop($id); $id; } I can't think of a portable definition of gethostname() that would be meaningful. Something close [:-)] would be: if Xenix, then read /etc/systemid; else if gethostname() is available, then gethostname(); else if uname() is available, then use nodename from utsname structure; else ""; Would anything be broken with this algorithm? -- Chip Salzenberg at ComDev/TCT , "The Usenet, in a very real sense, does not exist."