3 # Copyright (c) 1995-1997 Graham Barr <gbarr@pobox.com>. All rights reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the same terms as Perl itself.
7 package Net::DummyInetd;
14 use vars qw($VERSION);
17 $VERSION = do { my @r=(q$Revision: 1.6 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
27 vec($vec,fileno($listen),1) = 1;
29 while(select($r=$vec,undef,undef,undef))
31 my $sock = $listen->accept;
41 my $x = IO::Handle->new_from_fd($sock,"r");
42 open(STDIN,"<&=".fileno($x)) || die "$! $@";
45 my $y = IO::Handle->new_from_fd($sock,"w");
46 open(STDOUT,">&=".fileno($y)) || die "$! $@";
50 exec(@cmd) || carp "$! $@";
64 my $type = ref($self) || $self;
66 my $listen = IO::Socket::INET->new(Listen => 5, Proto => 'tcp');
69 return bless [ $listen->sockport, $pid ]
93 Net::DummyInetd - A dummy Inetd server
100 $inetd = new Net::DummyInetd qw(/usr/lib/sendmail -ba -bs);
102 $smtp = Net::SMTP->new('localhost', Port => $inetd->port);
106 C<Net::DummyInetd> is just what its name says, it is a dummy inetd server.
107 Creation of a C<Net::DummyInetd> will cause a child process to be spawned off
108 which will listen to a socket. When a connection arrives on this socket
109 the specified command is fork'd and exec'd with STDIN and STDOUT file
110 descriptors duplicated to the new socket.
112 This package was added as an example of how to use C<Net::SMTP> to connect
113 to a C<sendmail> process, which is not the default, via SIDIN and STDOUT.
114 A C<Net::Inetd> package will be available in the next release of C<libnet>
122 Creates a new object and spawns a child process which listens to a socket.
123 C<CMD> is a list, which will be passed to C<exec> when a new process needs
134 Returns the port number on which the I<DummyInetd> object is listening
140 Graham Barr <gbarr@pobox.com>
144 Copyright (c) 1995-1997 Graham Barr. All rights reserved.
145 This program is free software; you can redistribute it and/or modify
146 it under the same terms as Perl itself.