How can I bind() to a port number < 1024?

Answer Posted / chaitanya

The restriction on access to ports < 1024 is part of a (fairly weak) security scheme particular to UNIX. The intention is that servers (for example rlogind, rshd) can check the port number of the client, and if it is < 1024, assume the request has been properly authorised at the client end.

The practical upshot of this, is that binding a port number < 1024 is reserved to processes having an effective UID == root.

This can, occasionally, itself present a security problem, e.g. when a server process needs to bind a well-known port, but does not itself need root access (news servers, for example). This is often solved by creating a small program which simply binds the socket, then restores the real userid and exec()s the real server. This program can then be made setuid root.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How is a socket created?

693


Can a socket have multiple ports?

650


How to find other end of unix socket connection?

668


Are sockets files?

657


Where is the socket located?

648


What is socket address with example?

648


How can I force a socket to send the data in its buffer?

1277


What is socket address?

761


Why does it take so long to detect that the peer died?

1305


Why do I get EPROTO from read()?

1146


Why sockets are used?

673


Why do we need socket programming?

637


Are unix sockets faster than tcp?

647


Can multiple sockets use the same port?

646


What's the difference between impact sockets and regular sockets?

623