Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!texsun!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: adding gethostname to Perl Message-ID: <109119@convex.convex.com> Date: 21 Nov 90 20:29:04 GMT References: <10164@jpl-devvax.JPL.NASA.GOV> Sender: news@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 163 In article jbw@bucsf.bu.edu (Joe Wells) writes: >In article <10164@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: > > I'm still resisting adding gethostname, since there doesn't seem to be > a portable definition of what a host name actually is, where you derive it > from and whether it contains the domain. Not to mention the business that > gateways can have multiple names, one for each interface... > >Just think of this as your opportunity to set the standard. > >After all, if Perl does it that way it must be right ... The only advantage that I can see to putting it into perl is that it is different on different systems, something perl manages to gloss over in a lot of cases (see mkdir). Right now, I usually just use chop($host = `hostname`); unless I really want it to blaze, in which case I use: $host = &gethostname || 'Amnesiac'; sub gethostname { local($MAXHOSTNAMELEN) = 64; local($SYS_gethostname) = 87; local($name) = "\0" x $MAXHOSTNAMELEN; syscall($SYS_gethostname, $name, $MAXHOSTNAMELEN) $name; } But this is still evil, cause I should have done a require on syscall.pl and sys/param.pl instead (or ph if you can't get h2pl to work or want fatal errors.) And that system call isn't everywhere. Sometimes 'uuname -l' is better. Sometimes uname is. See attached material. It's just hard to know. That's about the only reason to put it there. But you already have to test system specific things, like icanon mode or whatnot. So it's probably not worth it. Now, it would be kinda nice to have if (__sun__ || __convex__) { so i don't have to go through the pre-processor. --tom Here's how your sitename is determined in rn's Configure. I guess Larry could add it to perl without asking the author's permission. :-) Pretty gross. : now get the site name $echo " " $echo "Figuring out site name..." $echo 'Maybe "hostname" will work...' if ans=`sh -c hostname 2>&1` ; then sitename=$ans hostcmd=hostname else $echo 'No, maybe "uuname -l" will work...' if ans=`sh -c 'uuname -l' 2>&1` ; then sitename=$ans hostcmd='uuname -l' else $echo 'Strange. Maybe "uname -n" will work...' if ans=`sh -c 'uname -n' 2>&1` ; then sitename=$ans hostcmd='uname -n' else $echo 'Oh well, maybe I can mine it out of whoami.h...' if ans=`sh -c $contains' sysname /usr/include/whoami.h' 2>&1` ; then sitename=`$echo "$ans" | $sed 's/^.*"\(.*\)"/\1/'` hostcmd="sed -n -e '"'/sysname/s/^.*\"\\(.*\\)\"/\1/{'"' -e p -e q -e '}'