Try a privileged port for binding whenever possible because the

ypbind daemon requires the ypserv daemon is running on a
privileged port.

Reported by:	Andrzej Tobola
This commit is contained in:
Hiroki Sato 2010-01-20 09:29:07 +00:00
parent e5c9c8533d
commit d04ef9128c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=202686

View File

@ -303,13 +303,18 @@ create_service(const int sock, const struct netconfig *nconf,
freeaddrinfo(res0); freeaddrinfo(res0);
return -1; return -1;
} }
if (bind(s, res->ai_addr, if (bindresvport_sa(s, res->ai_addr) == -1) {
res->ai_addrlen) == -1) { if ((errno != EPERM) ||
_msgout("cannot bind %s socket: %s", (bind(s, res->ai_addr,
nconf->nc_netid, strerror(errno)); res->ai_addrlen) == -1)) {
freeaddrinfo(res0); _msgout("cannot bind "
close(sock); "%s socket: %s",
return -1; nconf->nc_netid,
strerror(errno));
freeaddrinfo(res0);
close(sock);
return -1;
}
} }
if (nconf->nc_semantics != NC_TPI_CLTS) if (nconf->nc_semantics != NC_TPI_CLTS)
listen(s, SOMAXCONN); listen(s, SOMAXCONN);