Skip to content

Commit

Permalink
Provide help for users trying to bind to privileged ports.
Browse files Browse the repository at this point in the history
Closes #2098.
  • Loading branch information
ralight committed Apr 3, 2021
1 parent eead0d2 commit 983dc14
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,12 @@ static int net__socket_listen_tcp(struct mosquitto__listener *listener)
#endif

if(bind(sock, rp->ai_addr, rp->ai_addrlen) == -1){
#if defined(__linux__)
if(errno == EACCES){
log__printf(NULL, MOSQ_LOG_ERR, "If you are trying to bind to a privileged port (<1024), try using setcap and do not start the broker as root:");
log__printf(NULL, MOSQ_LOG_ERR, " sudo setcap 'CAP_NET_BIND_SERVICE=+ep /usr/sbin/mosquitto'");
}
#endif
net__print_error(MOSQ_LOG_ERR, "Error: %s");
COMPAT_CLOSE(sock);
freeaddrinfo(ainfo);
Expand Down

0 comments on commit 983dc14

Please sign in to comment.