SDSU CS 596: Client Server Programming
Server Stuff

[To Lecture Notes Index]
San Diego State University -- This page last updated March 8, 1995

  1. References for this lecture :
  2. inetd -- The internet super daemon
  3. /etc/services
  4. /etc/inetd.conf
  5. Sample use of fortune service
  6. Sample fortune client
  7. Servers started by inetd
  8. Standard Services provided by inetd
  9. Tcpwrappers
  10. Tcpwrappers (continued)
  11. Server Configuration files
  12. Location of server parameters
  13. Configuration files
  14. Example of BAD configuration file
  15. Configuration file issues
  16. Server code issues

References for this lecture:

inetd -- The internet super daemon

Starts servers on demand

Started from /etc/rc

Configuration file in /etc/inetd.conf

Other information from /etc/services



service-name port/protocol aliases

example (from

fortune 6665/tcp

ofortune 6666/tcp



service-name socket-type protocol wait-status uid server-program server-arguments

The name found in /etc/services.
Something like stream or dgram.
A valid protocol the system knows about
Either wait or nowait
The user the program will run as.
Full path the executable
The full argv array (5 max)

Sample use of fortune service

example entry for fortune server on

fortune stream tcp nowait nobody\ /usr/local/bin/fortune.real \ fortune

ofortune stream tcp nowait \ nobody /usr/local/bin/fortune.real\ fortune -o

% telnet sciences 6665


Connected to sciences.

Escape character is '^]'.

Just because your doctor has a name for your condition doesn't mean he knows what it is.

Connection closed by foreign host.


Sample fortune client

The /usr/etc/mconnect command is similar to telnet, but I/O can be redirected from it.

if [ X$1 = X ]; then	
/usr/etc/mconnect -p 6665 sciences | /usr/ucb/tail + 3
/usr/etc/mconnect -p 6666 sciences | /usr/ucb/tail + 3


% fortune


% fortune foo

Servers started by inetd

The connected socket is assigned to both stdin, stdout, and stderr.

Use the getpeername() call on fd 0 to find the peer's name.

Normally a server has an option which allows it to be started from inetd.

Is there a way to automatically tell if a server is started from inetd or not?

Standard Services provided by inetd

inetd itself provides a number of simple TCP services:


Server security without modification to the server.

Sample /etc/inetd.conf entry:

telnet stream tcp nowait root \ /usr/etc/tcpd telnetd

inetd runs tcpd instead of telnetd

/usr/etc/tcpd uses the following Files:

Tcpwrappers (continued)

Format of /etc/hosts.allow and /etc/hosts.deny:

daemon-list : client-list : [: shell-command ]

For example if we want to block all incoming telnet sessions from off-campus we do the following in /etc/hosts.allow:

telnetd : 130.191. :

and /etc/hosts.deny:

telnetd : ALL :

tcpwrappers can use the IDENT protocol to check for

incoming users.

Server Configuration files

Most servers need lots of information to work properly:

This information doesn't change from server start to server start

Location of server parameters

Assignment of values for parameters:

Configuration files

Helpful guidelines for configuration file design:

Examples of good configuration file formats

[GROUP Identifier]

name=value value

*.name: value

name: value

Example of BAD configuration file

Apple Macintosh Resources.

You have to use either Apple's 'resedit' or the application has to have its own interface.

Prime example of bad use of this is Mac Eudora (old)

The modem dialup script is entered using Resedit.

Configuration file issues

Allow for comments:

Use name/value pairs to set options:

Consistency is important!

database = /usr/local/lib/database

helpdatabase: /usr/local/lib/

Server code issues

Configuration file location is only one option

Server needs a standard interface to the configuration once it has read it.

If using consistent name/value pairs, a Dictionary or symbol table is a good interface.

The server can preload the dictionary with its own compiled defaults and then overwrite these with the configuration file.

This code should be reusable.