3 # Copyright (c) 1995 Graham Barr <Graham.Barr@tiuk.ti.com>. All rights
4 # reserved. 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;
11 Net::DummyInetd - A dummy Inetd server
18 $inetd = new Net::DummyInetd qw(/usr/lib/sendmail -ba -bs);
20 $smtp = Net::SMTP->new('localhost', Port => $inetd->port);
24 C<Net::DummyInetd> is just what it's name says, it is a dummy inetd server.
25 Creation of a C<Net::DummyInetd> will cause a child process to be spawned off
26 which will listen to a socket. When a connection arrives on this socket
27 the specified command is fork'd and exec'd with STDIN and STDOUT file
28 descriptors duplicated to the new socket.
30 This package was added as an example of how to use C<Net::SMTP> to connect
31 to a C<sendmail> process, which is not the default, via SIDIN and STDOUT.
32 A C<Net::Inetd> package will be avaliable in the next release of C<libnet>
40 Creates a new object and spawns a child process which listens to a socket.
41 C<CMD> is a list, which will be passed to C<exec> when a new process needs
52 Returns the port number on which the I<DummyInet> object is listening
58 Graham Barr <Graham.Barr@tiuk.ti.com>
64 The VERSION is derived from the revision by changing each number after the
65 first dot into a 2 digit number so
67 Revision 1.8 => VERSION 1.08
68 Revision 1.2.3 => VERSION 1.0203
72 Copyright (c) 1995 Graham Barr. All rights reserved. This program is free
73 software; you can redistribute it and/or modify it under the same terms
83 use vars qw($VERSION);
86 $VERSION = do{my @r=(q$Revision: 1.2 $=~/(\d+)/g);sprintf "%d."."%02d"x$#r,@r};
96 vec($vec,fileno($listen),1) = 1;
98 while(select($r=$vec,undef,undef,undef))
100 my $sock = $listen->accept;
110 my $x = IO::Handle->new_from_fd($sock,"r");
111 open(STDIN,"<&=".fileno($x)) || die "$! $@";
114 my $y = IO::Handle->new_from_fd($sock,"w");
115 open(STDOUT,">&=".fileno($y)) || die "$! $@";
119 exec(@cmd) || carp "$! $@";
133 my $type = ref($self) || $self;
135 my $listen = IO::Socket::INET->new(Listen => 5, Proto => 'tcp');
138 return bless [ $listen->sockport, $pid ]
141 _process($listen,@_);