Sockets: Server Design 1249
The /etc/inetd.conf file
The operation of the inetd daemon is controlled by a configuration file, normally
/etc/inetd.conf. Each line in this file describes one of the services to be handled by
inetd. Listing 60-5 shows some examples of entries in the /etc/inetd.conf file that
comes with one Linux distribution.
Listing 60-5: Example lines from /etc/inetd.conf
echo stream tcp nowait root internal
echo dgram udp wait root internal
ftp stream tcp nowait root /usr/sbin/tcpd in.ftpd
telnet stream tcp nowait root /usr/sbin/tcpd in.telnetd
login stream tcp nowait root /usr/sbin/tcpd in.rlogind
The first two lines of Listing 60-5 are commented out by the initial # character; we
show them now since we’ll refer to the echo service shortly.
Each line of /etc/inetd.conf consists of the following fields, delimited by white
space:
z Service name: This specifies the name of a service from the /etc/services file. In
conjunction with the protocol field, this is used to look up /etc/services to deter-
mine which port number inetd should monitor for this service.
z Socket type: This specifies the type of socket used by this service—for example,
stream or dgram.
z Protocol: This specifies the protocol to be used by this socket. This field can con-
tain any of the Internet protocols listed in the file /etc/protocols (documented
in the protocols(5) manual page), but almost every service specifies either tcp
(for TCP) or udp (for UDP).
z Flags: This field contains either wait or nowait. This field specifies whether or
not the server execed by inetd (temporarily) takes over management of the socket
for this service. If the execed server manages the socket, then this field is specified
as wait. This causes inetd to remove this socket from the file descriptor set that
it monitors using select() until the execed server exits (inetd detects this via a
handler for SIGCHLD). We say some more about this field below.
z Login name: This field consists of a username from /etc/passwd, optionally followed
by a period (.) and a group name from /etc/group. These determine the user
and group IDs under which the execed server is run. (Since inetd runs with an
effective user ID of root, its children are also privileged and can thus use calls to
setuid() and setgid() to change process credentials if desired.)
z Server program: This specifies the pathname of the server program to be execed.
z Server program arguments: This field specifies one or more arguments, separated
by white space, to be used as the argument list when execing the server program.
The first of these corresponds to argv[0] in the execed program and is thus usually
the same as the basename part of the server program name. The next argument
corresponds to argv[1], and so on.