[comp.protocols.tcp-ip] IP UDP/TCP port numbers

cyrus@hi.unm.edu (Tait Cyrus) (04/20/88)

What is the algorithm used by TCP and UDP to pick port numbers?  Specifically
I would like to know how the op sys picks src/dst port numbers.  

Let's say I have a socket between two machines.  How does the op sys keep
from picking port (socket) numbers that are defined in the RFC (RFC 1010)
or by UN*X in /etc/services?

The reason I ask is because will watching packets fly around on our
local network, I have seen machines use port numbers that should be
used ONLY for certain applications (who, timed, smtp, etc.).

TCP port numbers seem to be ok, but UDP port numbers seem to be totally
random.  I have seen many UDP packets in which BOTH the source AND
destination ports are zero (0).  According to UDP RFC (RFC 768), only
the src port can be zero "if not used".  The "destination port has a meaning
within the context of a particular internet destination address."  Ok,
what does this mean?  Under what circumstances can the op sys pick port
numbers (specifically dst port) that have predefined meanings?

Below is some example output from my monitoring:

	     UDP packets
	src port 0, dst port 1
	src port 0, dst port 3
	src port 0, dst port 6
	src port 0, dst port 8
	src port 0, dst port 12
	src port 0, dst port 'DISCARD'		DISCARD = 9
	src port 0, dst port 'RJE'		RJE = 5
	src port 0, dst port 'CHARGEN'		CHARGEN = 19
huh? -> src port 0, dst port 0
	src port 0, dst port 'ECHO'		ECHO = 7

What is going on?  I would appreciate it if someone could enlighten me
because I must be missing something.

-- 
    @__________@    W. Tait Cyrus   (505) 277-0806
   /|         /|    University of New Mexico
  / |        / |    Dept of Electrical & Computer Engineering 
 @__|_______@  |       Parallel Processing Research Group (PPRG)
 |  |       |  |       UNM/LANL Hypercube Project
 |  |  hc   |  |    Albuquerque, New Mexico 87131
 |  @.......|..@    
 | /        | /     e-mail:      
 @/_________@/        cyrus@hc.dspo.gov