Xref: utzoo alt.sources:1253 comp.protocols.tcp-ip.ibmpc:1972 Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!zephyr.ens.tek.com!tekcrl!tekfdi!videovax!bart From: bart@videovax.tv.tek.com (Bart Massey) Newsgroups: alt.sources,comp.protocols.tcp-ip.ibmpc Subject: Avoiding perl, UDP QOTD (Re: QOTD server (Re: Help with socket 'select')) Message-ID: <5633@videovax.tv.tek.com> Date: 27 Nov 89 22:16:49 GMT References: <13937@orstcs.CS.ORST.EDU> Reply-To: bart@videovax.tv.tek.com (Bart Massey) Followup-To: alt.sources.d Organization: Tektronix TV Measurement Systems, Beaverton OR Lines: 105 In article <13937@orstcs.CS.ORST.EDU> pvo3366@sapphire.OCE.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!! Note that for Berkeley-derived systems, at least, the above-referenced perl code is unnecessary -- inetd will do exactly the right thing. Try putting the following line in /etc/inetd.conf (or wherever you hide your inetd config). quote stream tcp nowait nobody /usr/games/fortune fortune -a This works great on my 4.3-Tahoe box. FTP Software's PC TCP/IP stuff includes a client known as "cookie", which uses the UDP version of the quote service. Since we have a bunch of those boxes here, I spent 15 minutes whacking together a UDP quote server which runs under inetd... cookie dgram udp wait nobody /usr/local/cookied cookied The following line should also be added to /etc/services. cookie 17/udp # FTP software's cookie server And here's the C code for the server. Yes, I know this isn't production quality, but I typed it in *really fast* :-). Please send patches with any bug reports, and be aware that I'm not really very interested in making it run on anything but 4BSD boxes... Bart Massey ..tektronix!videovax.tv.tek.com!bart ..tektronix!reed.bitnet!bart /* --- cut here ----- /* * cookied.c -- UDP fortune server * Bart Massey 11/27/89 */ #include #include #include #include #include #include #define FORTUNEBUFSIZE (64 * 1024) #define FORTUNEPROG "/usr/bin/fortune -a" main(argc, argv) int argc; char **argv; { char *fortunebuf, *fbp; FILE *pfile; int nextchar, fromlen; struct sockaddr_in from; extern char *malloc(); openlog( argv[0], LOG_PID|LOG_NOWAIT, LOG_DAEMON ); fortunebuf = malloc( FORTUNEBUFSIZE ); if( !fortunebuf ) { syslog( LOG_ERR, "out of memory" ); exit( 1 ); } fromlen = sizeof( from ); if( recvfrom( 0, fortunebuf, FORTUNEBUFSIZE, 0, (struct sockaddr *) &from, &fromlen ) == -1 ) { syslog( LOG_ERR, "recvfrom: %m" ); exit( 1 ); } pfile = popen( FORTUNEPROG, "r" ); if( !pfile ) { syslog( LOG_ERR, "popen \"%s\": %m", FORTUNEPROG ); exit( 1 ); } for( fbp = fortunebuf; fbp < fortunebuf + FORTUNEBUFSIZE; fbp++ ) { nextchar = getc( pfile ); if( nextchar == EOF ) { *fbp = '\0'; /* we don't *send* this, but... */ break; } *fbp = nextchar; } if( nextchar != EOF ) { syslog( LOG_ERR, "buffer too small" ); exit( 1 ); } pclose( pfile ); if( sendto( 0, fortunebuf, fbp - fortunebuf, 0, &from, fromlen ) == -1 ) { syslog( LOG_ERR, "send: %m" ); exit( 1 ); } syslog( LOG_DEBUG, "sent fortune to %s (%d)", inet_ntoa( * (long *) (&from.sin_addr) ), ntohs( from.sin_port ) ); exit( 0 ); } Brought to you by Super Global Mega Corp .com