Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!psuvax1!rutgers!orstcs!pvo3366 From: pvo3366@sapphire.OCE.ORST.EDU (Paul O'Neill) Newsgroups: alt.sources Subject: QOTD server (Re: Help with socket 'select') Message-ID: <13937@orstcs.CS.ORST.EDU> Date: 22 Nov 89 08:15:19 GMT Sender: usenet@orstcs.CS.ORST.EDU Organization: Coastal Imaging Lab, Oregon State University, Corvallis, OR Lines: 52 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 () { 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