Reputation: 965
I am writing a C++ application that accepts HTTP request from browser and sending back the response.
int port = 2127; //80;
int bind_res = ::bind(port, p_ref->ai_addr, p_ref->ai_addrlen);
The application works as expected on OSX when I set it to listen at port 2127. But when I set it to listen on port 80, the application stopped working with exception:
server: bind: Permission denied
My application is a command line application, and it opened by other GUI application, also written in C++ but with Qt.
How can I gain enough privilege to bind to port 80? Is there any API to show user and password prompt - like in XAMPP Control Panel, for example - to get those privilege?
EDIT: I write the app for running on OSX 10.8 Mountain Lion.
Upvotes: 0
Views: 627
Reputation: 11011
Usually you cannot bind because of two issues:
It feels you have problem with that second case. For running with super user privileges there is sudo
command on all Unixes (OSX is Unix).
If you do not like sudo
then you can permanently redirect the port to other port that can be bound by user.
Upvotes: 1