[comp.unix.wizards] Portmapper question

ldk@raistlin (ld kelley x-6857) (06/01/91)

When the portmapper assigns ports to programs that are registering, how does
it keep from using ports that are reserved (via the services file) for
other programs?

Please answer by email, I will summarize later.

thanks in advance,
larry

-- 
Larry D. Kelley ARH215  |      Internet:  ldk@raistlin.udev.cdc.com
Control Data Corporation|      uucp:      {uunet}!shamash!raistlin!ldk
4201 Lexington Ave No.  |      AT&T:	  01-612-482-2046
Arden Hills, MN         |

mouse@thunder.mcrcim.mcgill.edu (der Mouse) (06/06/91)

In article <33719@shamash.cdc.com>, ldk@raistlin (ld kelley x-6857) writes:

> When the portmapper assigns ports to programs that are registering,
> how does it keep from using ports that are reserved (via the services
> file) for other programs?

You don't say what sort of system you're talking about, so I'll use the
handiest one I have access to which has a portmapper.  This is a Sun
running SunOS 4.1.

With that out of the way...the portmapper *doesn't* assign ports;
clients tell it what port they're listening on.

Clients then come in two flavors: those that use a port dedicated to
their use and those that use just any old port.  (The former are rare,
precisely because of the portmapper's existence; NFS is the only one
that comes to mind, and that for historical reasons.)  Your question
doesn't really apply to the former, and for the latter, it's avoided
because when the client binds to "just any port", the kernel picks the
port, and it picks ports from a restricted range.  From <netinet/in.h>:

	/*
	 * Ports < IPPORT_RESERVED are reserved for
	 * privileged processes (e.g. root).
	 * Ports > IPPORT_USERRESERVED are reserved
	 * for servers, not necessarily privileged.
	 */
	#define IPPORT_RESERVED         1024
	#define IPPORT_USERRESERVED     5000

Thus, by implication, the kernel will never assign a port number
outside of [1024..5000].  Now if only we had some assurance that
everybody used the same technique with the same numbers....

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu