sockets

Jonathan I. Kamens jik at athena.mit.edu
Fri Jun 8 21:45:49 AEST 1990


In article <4444 at infmx.UUCP>, kevinf at infmx.UUCP (Kevin Franden) writes:
|> 	1) When does /etc/services come into play?  I was able to talk
|> 	   over port 6000 w/ no trouble (SOCK_STREAM) WITHOUT having
|> 	   an entry in /etc/services.  Which leads me to wonder what 
|> 	   exactly /etc/services does anyway.  Was this a cardinal sin?
|> 	   Very dangerous?  Very stupid?  All of the above?

/etc/services is a database which links services (and protocols) to port
numbers.  You don't *have* to use /etc/services to connect to any
particular port.  Its purpose is to give you a record of which ports are
reserved and which are not, and also to allow you to refer to services
by their names rather than by their port numbers.

Let's say that you and I are developing new services that will
eventually be used a lot on the Internet.  We need to choose ports to
work on until we're assigned one officially, and by coincidence (we
don't know each other, of course :-), we both choose the same port.

Well, when we bump into each other and discover that one of us has to
change ports, then either it's going to be very easy (editing
/etc/services to change the port number, since the program looks up the
service by name rather than having the number hard-coded), or a bit
harder (recompiling the program because the port is hard-coded.

|> 	2) If I understnd correctly (which I probably don't) I can 
|> 	   use inetd to start up my executable if there's a request
|> 	   on that port.  Will one of the true net.wizards help this
|> 	   fledgling.wizard by explaining the functions of all these 
|> 	   files?

The file /etc/inetd.conf associates service names from /etc/services
with the programs which should be run when a connection is established
on a service port.  When a daemon is run by inetd after inetd gets a
connection on that daemon's port, the stdin and stdout of the daemon are
connected to the socket which inetd get when it accepted the connection.

This is explained pretty clearly (all except the part about stdin and
stdout, which you're just supposed to know :-) in the man page for inetd.

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710



More information about the Comp.unix.wizards mailing list