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



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

Answer / 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

More Unix Socket Programming Interview Questions

Where can a get a library for programming sockets?

1 Answers  


Where is the socket located?

0 Answers  


What is socket address?

0 Answers  


Why sockets are used?

0 Answers  


Are unix sockets faster than tcp?

0 Answers  






Is a socket a file?

0 Answers  


How many sockets can a port have?

0 Answers  


How do I properly close a socket?

1 Answers  


What is with the second parameter in bind()?

1 Answers  


What is socket address with example?

0 Answers  


Why do we need sockets?

0 Answers  


Why do I get connection refused when the server is not running?

1 Answers  


Categories