QOTD server (Re: Help with socket 'select')

Paul O'Neill pvo3366 at sapphire.OCE.ORST.EDU
Wed Nov 22 19:15:19 AEST 1989


Only a few hosts in the NIC host tables advertise supporting QOTD service.
(Quote of the day.)  This should change that!!
 
------------------------------------------------
 
#!/usr/bin/perl 
# server.qotd -- QOTD (qoute of the day) server -- from the perl man page
#
# ######## usage: server.qotd /usr/games/fortune_or_whatever  #############
#
# Paul O'Neill
# 21 nov 89
# exercise w/ ``telnet server_host 17'' from any host
         
$port = 17;
 
do 'sys/socket.h' || die "Can't do sys/socket.h: $@"; #see makelib for
                                                      #generating socket.h
$sockaddr = 'S n a4 x8';
 
($name, $aliases, $proto) = getprotobyname('tcp');
 
$this = pack($sockaddr, &AF_INET, $port, "\0\0\0\0");
select(NS); $| = 1; select(stdout);
 
socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "socket: $!";
bind(S, $this) || die "bind: $!";
listen(S, 5) || die "connect: $!";
 
select(S); $| = 1; select(stdout);
 
for (;;) {
     ($addr = accept(NS,S)) || die $!;
     open(QOTD, "$ARGV[0] |");

     while (<QOTD>) {
          print NS;
     }
}

-------------------------------

ps -- Just for giggles, try a

        telnet sapphire.oce.orst.edu 17


Paul O'Neill                 pvo at oce.orst.edu
Coastal Imaging Lab
OSU--Oceanography
Corvallis, OR  97331         503-754-3251



More information about the Alt.sources mailing list