genserv : A Generic Network Server Program

  by Chad Clark    

The Beginning

Supose you have a program written in a language where you don't want to learn how to deal with network sockets or maybe a language that doesn't support sockets directly such as Bash. What if you want to make this program available on a network? Well you could write a web based front end. I chose to write genserv (from Generic or General Server).

The Idea

This works because of the way Linux handles network connections as files.
The application doesn't need to even know the network connection exists.

The Code

The code is all in one C file.
There is also a makefile but it's really simple and is only used because I like make.
Just put both files in one directory and type make.

Using genserv

From the program's usage description:
         ./genserv port_num program_name args
  "port_num" is a valid TCP port number.
  "program_name" is a program to be run when a client connects.
  "args" is an optional list of arguments to the program to be executed.

eg: ./genserv 12345 /usr/bin/uptime
    will listen on port 12345 and print the uptime string then exit.

eg: ./genserv 12345 /usr/bin/uptime -V
    will listen on port 12345 and print the uptime version then exit.

In the future I want to add some sort of basic authentication scheme.
Most likely just a password that is set when genserv is started.
Currently there is no authentication build into genserv so any programs
which get run from genserv need to either do their own authentications
or be open to the network.

It may also be usefull/interesting to read the Secure Programming for Linux and Unix HOWTO
if you have to write programs which other people will be running.


All of my work was done a stock Slackware Linux 8.1 machine.

To test the program run ./genserv 12321 ls -l .
From another TTY telnet to port 12321 (eg telnet 12321 ).
You should see something like:
[frink@thepurplebuffalo ~/code/cxx/genserv]$telnet 12321 Trying Connected to Escape character is '^]'. total 32 drwx------ 2 frink users 4096 May 17 18:00 CVS -rw-r--r-- 1 frink users 94 May 17 21:46 Makefile -rwx------ 1 frink users 16693 May 17 21:46 genserv -rw-r--r-- 1 frink users 3887 May 17 21:46 genserv.c -rw------- 1 frink users 0 May 17 21:47 typescript Connection closed by foreign host. [frink@thepurplebuffalo ~/code/cxx/genserv]$

Known Bugs