Should I bind() a port number in my client program, or let thesystem choose one for me on the connect() call?
From Andrew Gierth ( andrew@erlenstar.demon.co.uk): ** Let the system choose your client’s port number ** The exception to this, is if the server has been written to be picky about what client ports it will allow connections from. Rlogind and rshd are the classic examples. This is usually part of a Unix-specific (and rather weak) authentication scheme; the intent is that the server allows connections only from processes with root privilege. (The weakness in the scheme is that many O/Ss (e.g. MS-DOS) allow anyone to bind any port.) The rresvport() routine exists to help out clients that are using this scheme. It basically does the equivalent of socket() + bind(), choosing a port number in the range 512..1023. If the server is not fussy about the client’s port number, then don’t try and assign it yourself in the client, just let connect() pick it for you. If, in a client, you use the naive scheme of starting at a fixed port number and calling bind() on consecutive values until it works,