[PLUG] Working with learning Perl by Randal Schwartz...

Kyle Hayes kyle at silverbeach.net
Sat Oct 25 12:42:01 UTC 2003


On Saturday 25 October 2003 12:22, Michael C. Robinson wrote:
> I'm curious about using xinetd now to do this.  I believe I can
> put the socket in /etc/services and then write an xinetd
> file for it, but what's the syntax?  Is this similar to
> remapping standard input to a socket?  What do I need in my perl
> script on the end serving the variables up to feed them to the
> socket on the other end?

Yep, service name in /etc/services along with port number, type (tcp/udp) etc.  
'man 5 services' will tell you how that works.

'man 5 xinetd.conf' will give you all the info you need to write an addition 
to xinetd.conf.

inetd/xinetd do basically the same thing.  They listen on the ports described 
in the conf file.  When something connects (for TCP ports), they look up what 
other program to start and remap the incoming side of the socket to STDIN of 
that program and the outgoing side to STDOUT.  The program is run once per 
connection and should terminate when done processing that one connection.

In your program, you just read/write to STDIN/STDOUT.  Just like you were 
running it on the command line.  It makes testing a snap.

inetd/xinetd are not meant for services that get hit a lot.  You really, 
really would not want to run a web server through it!  However, it is 
reasonable to run other things through it.

Here's a shell script that tells you who is online:

----------------------
#!/bin/sh

who
----------------------

Put that in /usr/local/bin or something.  Lash that up into xinetd.conf and it 
will return the output of the 'who' command to the thing connecting to the 
socket.

If you need a really simple way to test the client side, I would suggest the 
netcat tool (often called nc, but so are a lot of other things).  Search on 
Google for it.  On SuSE machines, it is called netcat.

$ netcat localhost <who port>

That will return the output of the above script if you've got xinetd 
configured correctly.

Don't forget to SIGHUP xinetd if you change the config!  That's my favorite 
way to confuse myself for a while.

inetd-style stuff is insanely useful for small hacks, but don't use it for 
high-volume services.  It can be tightened down (in xinetd.conf) pretty well 
too.

Best,
Kyle





More information about the PLUG mailing list