[alt.sources] QOTD server

pvo3366@sapphire.OCE.ORST.EDU (Paul O'Neill) (11/22/89)

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@oce.orst.edu
Coastal Imaging Lab
OSU--Oceanography
Corvallis, OR  97331         503-754-3251

dupuy@cs.columbia.edu (Alexander Dupuy) (11/23/89)

In article <13937@orstcs.CS.ORST.EDU> Paul O'Neill writes:

> Only a few hosts in the NIC host tables advertise supporting QOTD service.
> (Quote of the day.)  This should change that!!
> 
> [perl script deleted]
> 
> ps -- Just for giggles, try a
> 
> 	telnet sapphire.oce.orst.edu 17

Why is it that everybody thinks perl is great for everything.  I'm sure it has
its uses, but its only one tool - there are lots of others.  Here's a simpler
version of the same thing that doesn't require perl, weird perl socket support,
or a separate deamon process:

$ grep quote /etc/inetd.conf
quote   stream  tcp     nowait  nobody  /usr/local/etc/in.qotdd in.quotdd

$ cat /usr/local/etc/in.quotdd
#!/bin/sh
#!/bin/sh
exec 1>&0 2>&0
echo ''
PATH=$PATH:/usr/games
exec "${@-/usr/games/fortune}"

$

What could be simpler?  And besides, it works:

$ telnet sapphire.oce.orst.edu 17
Trying 128.193.64.35 ...
telnet: connect: Connection refused
telnet> open localhost 17
Trying 127.0.0.1 ...
Connected to localhost.columbia.edu.
Escape character is '^]'.

Ken Thompson has an automobile which he helped design.  Unlike most
automobiles, it has neither speedometer, nor gas gage, nor any of the
numerous idiot lights which plague the modern driver.  Rather, if the
driver makes any mistake, a giant "?" lights up in the center of the
dashboard.  "The experienced driver", he says, "will usually know
what's wrong."
Connection closed by foreign host.

$ 

@alex
--
-- 
inet: dupuy@cs.columbia.edu
uucp: ...!rutgers!cs.columbia.edu!dupuy