Failed to listen to or bind port 80 in Linux

Source: Internet
Author: User

I wrote a program and tried to listen on port 80. As a result, the execution of the bind failed.
The program is as follows:

 

Sockaddr_in sock_addr;
Memset (& sock_addr, 0, sizeof (sock_addr ));
Sock_addr.sin_family = AF_INET;
Sock_addr.sin_addr.s_addr = host_inet_addr;
Sock_addr.sin_port = htons (m_local_port); // m_local_port = 80
Ret = bind (m_socket_fd, (const sockaddr *) & sock_addr, sizeof (sockaddr_in ));


Ret is-1.
Then, change m_local_port to 8080. Suddenly, the system does not allow user programs to listen on Ports 1-because they are well-known ports.
So how can I listen on a well-known port? Obviously, there are no programs running on port 80 on my machine, so there must be a way, not at my program level.
Therefore, if su is used and replaced with the root user, the bind is successful.

Record it.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.