ext/Socket/Makefile.PL Socket extension makefile writer
ext/Socket/Socket.pm Socket extension Perl module
ext/Socket/Socket.xs Socket extension external subroutines
+ext/Sys/Hostname/Makefile.PL Sys::Hostname extension makefile writer
+ext/Sys/Hostname/Hostname.pm Sys::Hostname extension Perl module
+ext/Sys/Hostname/Hostname.xs Sys::Hostname extension external subroutines
ext/Sys/Syslog/Makefile.PL Sys::Syslog extension makefile writer
ext/Sys/Syslog/Syslog.pm Sys::Syslog extension Perl module
ext/Sys/Syslog/Syslog.xs Sys::Syslog extension external subroutines
lib/SelfLoader.pm Load functions only on demand
lib/Shell.pm Make AUTOLOADed system() calls
lib/Symbol.pm Symbol table manipulation routines
-lib/Sys/Hostname.pm Hostname methods
lib/Term/Cap.pm Perl module supporting termcap usage
lib/Term/Complete.pm A command completion subroutine
lib/Term/ReadLine.pm Stub readline library
'XSLoader_pm.PL'=>'XSLoader.pm'},
PM => {'DynaLoader.pm' => '$(INST_LIBDIR)/DynaLoader.pm',
'XSLoader.pm' => '$(INST_LIBDIR)/XSLoader.pm'},
- clean => {FILES => 'DynaLoader.c DynaLoader.xs DynaLoader.pm'},
+ clean => {FILES => 'DynaLoader.c DynaLoader.xs DynaLoader.pm ' .
+ 'XSLoader.pm'},
);
sub MY::postamble {
package Sys::Hostname;
-use Carp;
-require Exporter;
-@ISA = qw(Exporter);
-@EXPORT = qw(hostname);
-
-=head1 NAME
-
-Sys::Hostname - Try every conceivable way to get hostname
-
-=head1 SYNOPSIS
-
- use Sys::Hostname;
- $host = hostname;
-
-=head1 DESCRIPTION
+use strict;
-Attempts several methods of getting the system hostname and
-then caches the result. It tries C<syscall(SYS_gethostname)>,
-C<`hostname`>, C<`uname -n`>, and the file F</com/host>.
-If all that fails it C<croak>s.
+use Carp;
-All nulls, returns, and newlines are removed from the result.
+require Exporter;
+use XSLoader ();
+require AutoLoader;
-=head1 AUTHOR
+our @ISA = qw/ Exporter AutoLoader /;
+our @EXPORT = qw/ hostname /;
-David Sundstrom E<lt>F<sunds@asictest.sc.ti.com>E<gt>
+our $VERSION = '1.1';
-Texas Instruments
+our $host;
-=cut
+XSLoader::load 'Sys::Hostname', $VERSION;
sub hostname {
# method 1 - we already know it
return $host if defined $host;
+ # method 1' - try to ask the system
+ $host = ghname();
+ return $host if defined $host;
+
if ($^O eq 'VMS') {
# method 2 - no sockets ==> return DECnet node name
return $host;
}
else { # Unix
+ # is anyone going to make it here?
# method 2 - syscall is preferred since it avoids tainting problems
+ # XXX: is it such a good idea to return hostname untainted?
eval {
local $SIG{__DIE__};
require "syscall.ph";
# method 6 - Apollo pre-SR10
|| eval {
local $SIG{__DIE__};
+ my($a,$b,$c,$d);
($host,$a,$b,$c,$d)=split(/[:\. ]/,`/com/host`,6);
}
}
1;
+
+__END__
+
+=head1 NAME
+
+Sys::Hostname - Try every conceivable way to get hostname
+
+=head1 SYNOPSIS
+
+ use Sys::Hostname;
+ $host = hostname;
+
+=head1 DESCRIPTION
+
+Attempts several methods of getting the system hostname and
+then caches the result. It tries the first available of the C
+library's gethostname(), C<`$Config{aphostname}`>, uname(2),
+C<syscall(SYS_gethostname)>, C<`hostname`>, C<`uname -n`>,
+and the file F</com/host>. If all that fails it C<croak>s.
+
+All NULs, returns, and newlines are removed from the result.
+
+=head1 AUTHOR
+
+David Sundstrom E<lt>F<sunds@asictest.sc.ti.com>E<gt>
+
+Texas Instruments
+
+XS code added by Greg Bacon E<lt>F<gbacon@cs.uah.edu>E<gt>
+
+=cut
+
--- /dev/null
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+#if defined(I_UNISTD) && defined(HAS_GETHOSTNAME)
+# include <unistd.h>
+#endif
+
+/* a reasonable default */
+#ifndef MAXHOSTNAMELEN
+# define MAXHOSTNAMELEN 256
+#endif
+
+/* swiped from POSIX.xs */
+#if defined(__VMS) && !defined(__POSIX_SOURCE)
+# if ((__VMS_VER >= 70000000) && (__DECC_VER >= 50200000)) || (__CRTL_VER >= 70000000)
+# include <utsname.h>
+# endif
+#endif
+
+#if defined(HAS_UNAME) && !defined(WIN32)
+/* XXX need i_sys_utsname in config.sh */
+# include <sys/utsname.h>
+#endif
+
+MODULE = Sys::Hostname PACKAGE = Sys::Hostname
+
+void
+ghname()
+ PREINIT:
+ IV retval = -1;
+ SV *sv;
+ PPCODE:
+ EXTEND(SP, 1);
+#ifdef HAS_GETHOSTNAME
+ {
+ char tmps[MAXHOSTNAMELEN];
+ retval = PerlSock_gethostname(tmps, sizeof(tmps));
+ sv = newSVpvn(tmps, strlen(tmps));
+ }
+#else
+# ifdef HAS_PHOSTNAME
+ {
+ PerlIO *io;
+ char tmps[MAXHOSTNAMELEN];
+ char *p = tmps;
+ char c;
+ io = PerlProc_popen(PHOSTNAME, "r");
+ if (!io)
+ goto check_out;
+ while (PerlIO_read(io, &c, sizeof(c)) == 1) {
+ if (isSPACE(c) || p - tmps >= sizeof(tmps))
+ break;
+ *p++ = c;
+ }
+ PerlProc_pclose(io);
+ *p = '\0';
+ retval = 0;
+ sv = newSVpvn(tmps, strlen(tmps));
+ }
+# else
+# ifdef HAS_UNAME
+ {
+ struct utsname u;
+ if (PerlEnv_uname(&u) == -1)
+ goto check_out;
+ sv = newSVpvn(u.nodename, strlen(u.nodename));
+ retval = 0;
+ }
+# endif
+# endif
+#endif
+ check_out:
+ if (retval == -1)
+ XSRETURN_UNDEF;
+ else
+ PUSHs(sv_2mortal(sv));
--- /dev/null
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'Sys::Hostname',
+ VERSION_FROM => 'Hostname.pm',
+ MAN3PODS => {}, # Pods will be built by installman.
+ XSPROTOARG => '-noprototypes',
+);
WriteMakefile(
NAME => 'Sys::Syslog',
VERSION_FROM => 'Syslog.pm',
+ MAN3PODS => {}, # Pods will be built by installman.
XSPROTOARG => '-noprototypes',
);
Perl now allows the arrow to be omitted in many constructs
involving subroutine calls through references. For example,
-C<$foo[10]->('foo')> may now be written C<$foo[10]('foo')>.
+C<$foo[10]-E<gt>('foo')> may now be written C<$foo[10]('foo')>.
This is rather similar to how the arrow may be omitted from
-C<$foo[10]->{'foo'}>. Note however, that the arrow is still
-required for C<foo(10)->('bar')>.
+C<$foo[10]-E<gt>{'foo'}>. Note however, that the arrow is still
+required for C<foo(10)-E<gt>('bar')>.
=head2 exists() is supported on subroutine names
=head2 File and directory handles can be autovivified
-Similar to how constructs such as C<$x->[0]> autovivify a reference,
+Similar to how constructs such as C<$x-E<gt>[0]> autovivify a reference,
handle constructors (open(), opendir(), pipe(), socketpair(), sysopen(),
socket(), and accept()) now autovivify a file or directory handle
if the handle passed to them is an uninitialized scalar variable. This
=head2 Pseudo-hashes work better
Dereferencing some types of reference values in a pseudo-hash,
-such as C<$ph->{foo}[1]>, was accidentally disallowed. This has
+such as C<$ph-E<gt>{foo}[1]>, was accidentally disallowed. This has
been corrected.
When applied to a pseudo-hash element, exists() now reports whether
Sys::Syslog now uses XSUBs to access facilities from syslog.h so it
no longer requires syslog.ph to exist.
+=item Sys::Hostname
+
+Sys::Hostname now uses XSUBs to call the C library's gethostname() or
+uname() if they exist.
+
=item Time::Local
The timelocal() and timegm() functions used to silently return bogus
print "1..0\n" if $@ =~ /Cannot get host name/;
} else {
print "1..1\n";
+ print "# \$host = `$host'\n";
print "ok 1\n";
}
!ENDIF
DYNAMIC_EXT = Socket IO Fcntl Opcode SDBM_File POSIX attrs Thread B re \
- Data/Dumper Devel/Peek ByteLoader Devel/DProf File/Glob
+ Data/Dumper Devel/Peek ByteLoader Devel/DProf File/Glob \
+ Sys/Hostname
STATIC_EXT = DynaLoader
NONXS_EXT = Errno
BYTELOADER = $(EXTDIR)\ByteLoader\ByteLoader
DPROF = $(EXTDIR)\Devel\DProf\DProf
GLOB = $(EXTDIR)\File\Glob\Glob
+HOSTNAME = $(EXTDIR)\Sys\Hostname\Hostname
SOCKET_DLL = $(AUTODIR)\Socket\Socket.dll
FCNTL_DLL = $(AUTODIR)\Fcntl\Fcntl.dll
BYTELOADER_DLL = $(AUTODIR)\ByteLoader\ByteLoader.dll
DPROF_DLL = $(AUTODIR)\Devel\DProf\DProf.dll
GLOB_DLL = $(AUTODIR)\File\Glob\Glob.dll
+HOSTNAME_DLL = $(AUTODIR)\Sys\Hostname\Hostname.dll
ERRNO_PM = $(LIBDIR)\Errno.pm
$(B).c \
$(BYTELOADER).c \
$(DPROF).c \
- $(GLOB).c
+ $(GLOB).c \
+ $(HOSTNAME).c
EXTENSION_DLL = \
$(SOCKET_DLL) \
$(THREAD_DLL) \
$(BYTELOADER_DLL) \
$(DPROF_DLL) \
- $(GLOB_DLL)
+ $(GLOB_DLL) \
+ $(HOSTNAME_DLL)
EXTENSION_PM = \
$(ERRNO_PM)
$(MAKE)
cd ..\..\win32
+$(HOSTNAME_DLL): $(PERLEXE) $(HOSTNAME).xs
+ cd $(EXTDIR)\Sys\$(*B)
+ ..\..\..\miniperl -I..\..\..\lib Makefile.PL INSTALLDIRS=perl
+ $(MAKE)
+ cd ..\..\..\win32
+
$(BYTELOADER_DLL): $(PERLEXE) $(BYTELOADER).xs
cd $(EXTDIR)\$(*B)
..\..\miniperl -I..\..\lib Makefile.PL INSTALLDIRS=perl
.ENDIF
DYNAMIC_EXT = Socket IO Fcntl Opcode SDBM_File POSIX attrs Thread B re \
- Data/Dumper Devel/Peek ByteLoader Devel/DProf File/Glob
+ Data/Dumper Devel/Peek ByteLoader Devel/DProf File/Glob \
+ Sys/Hostname
STATIC_EXT = DynaLoader
NONXS_EXT = Errno
BYTELOADER = $(EXTDIR)\ByteLoader\ByteLoader
DPROF = $(EXTDIR)\Devel\DProf\DProf
GLOB = $(EXTDIR)\File\Glob\Glob
+HOSTNAME = $(EXTDIR)\Sys\Hostname\Hostname
SOCKET_DLL = $(AUTODIR)\Socket\Socket.dll
FCNTL_DLL = $(AUTODIR)\Fcntl\Fcntl.dll
BYTELOADER_DLL = $(AUTODIR)\ByteLoader\ByteLoader.dll
DPROF_DLL = $(AUTODIR)\Devel\DProf\DProf.dll
GLOB_DLL = $(AUTODIR)\File\Glob\Glob.dll
+HOSTNAME_DLL = $(AUTODIR)\Sys\Hostname\Hostname.dll
ERRNO_PM = $(LIBDIR)\Errno.pm
$(B).c \
$(BYTELOADER).c \
$(DPROF).c \
- $(GLOB).c
+ $(GLOB).c \
+ $(HOSTNAME).c
EXTENSION_DLL = \
$(SOCKET_DLL) \
$(THREAD_DLL) \
$(BYTELOADER_DLL) \
$(DPROF_DLL) \
- $(GLOB_DLL)
+ $(GLOB_DLL) \
+ $(HOSTNAME_DLL)
EXTENSION_PM = \
$(ERRNO_PM)
..\..\miniperl -I..\..\lib Makefile.PL INSTALLDIRS=perl
cd $(EXTDIR)\$(*B) && $(MAKE)
+$(HOSTNAME_DLL): $(PERLEXE) $(HOSTNAME).xs
+ cd $(EXTDIR)\Sys\$(*B) && \
+ ..\..\..\miniperl -I..\..\..\lib Makefile.PL INSTALLDIRS=perl
+ cd $(EXTDIR)\Sys\$(*B) && $(MAKE)
+
$(BYTELOADER_DLL): $(PERLEXE) $(BYTELOADER).xs
cd $(EXTDIR)\$(*B) && \
..\..\miniperl -I..\..\lib Makefile.PL INSTALLDIRS=perl