Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Should I bind() a port number in my client program, or let thesystem choose one for me on the connect() call?

0
Posted

Should I bind() a port number in my client program, or let thesystem choose one for me on the connect() call?

0

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,

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123