1 diff --git a/src/rpcbind.c b/src/rpcbind.c
2 index 63023e1..310c243 100644
5 @@ -275,7 +275,7 @@ init_transport(struct netconfig *nconf)
6 int status; /* bound checking ? */
13 struct sockaddr *sa = NULL;
14 @@ -301,18 +301,6 @@ init_transport(struct netconfig *nconf)
19 - * XXX - using RPC library internal functions. For NC_TPI_CLTS
20 - * we call this later, for each socket we like to bind.
22 - if (nconf->nc_semantics != NC_TPI_CLTS) {
23 - if ((fd = __rpc_nconf2fd(nconf)) < 0) {
24 - syslog(LOG_ERR, "cannot create socket for %s",
30 if (!__rpc_nconf2sockinfo(nconf, &si)) {
31 syslog(LOG_ERR, "cannot get information for %s",
33 @@ -335,8 +323,6 @@ init_transport(struct netconfig *nconf)
34 hints.ai_family = si.si_af;
35 hints.ai_socktype = si.si_socktype;
36 hints.ai_protocol = si.si_proto;
38 - if (nconf->nc_semantics == NC_TPI_CLTS) {
40 * If no hosts were specified, just bind to INADDR_ANY. Otherwise
41 * make sure 127.0.0.1 is added to the list.
42 @@ -354,21 +340,15 @@ init_transport(struct netconfig *nconf)
48 - * Bind to specific IPs if asked to
51 - while (nhostsbak > 0) {
54 - * XXX - using RPC library internal functions.
56 - if ((fd = __rpc_nconf2fd(nconf)) < 0) {
57 - syslog(LOG_ERR, "cannot create socket for %s",
63 + * Bind to specific IPs if asked to
66 + while (nhostsbak > 0) {
68 + if ((strcmp(nconf->nc_netid, "local") != 0) &&
69 + (strcmp(nconf->nc_netid, "unix") != 0)) {
70 switch (hints.ai_family) {
72 if (inet_pton(AF_INET, hosts[nhostsbak],
73 @@ -395,7 +375,7 @@ init_transport(struct netconfig *nconf)
82 @@ -418,97 +398,37 @@ init_transport(struct netconfig *nconf)
84 addrlen = res->ai_addrlen;
85 sa = (struct sockaddr *)res->ai_addr;
86 - oldmask = umask(S_IXUSR|S_IXGRP|S_IXOTH);
87 - if (bind(fd, sa, addrlen) != 0) {
88 - syslog(LOG_ERR, "cannot bind %s on %s: %m",
89 - (hosts[nhostsbak] == NULL) ? "*" :
90 - hosts[nhostsbak], nconf->nc_netid);
96 - (void) umask(oldmask);
99 - /* Copy the address */
100 - taddr.addr.maxlen = taddr.addr.len = addrlen;
101 - taddr.addr.buf = malloc(addrlen);
102 - if (taddr.addr.buf == NULL) {
104 - "cannot allocate memory for %s address",
107 + * XXX - using RPC library internal functions.
109 + if ((fd = __rpc_nconf2fd(nconf)) < 0) {
110 + syslog(LOG_ERR, "cannot create socket for %s",
114 + oldmask = umask(S_IXUSR|S_IXGRP|S_IXOTH);
115 + if (nconf->nc_semantics != NC_TPI_CLTS) {
116 + __rpc_fd2sockinfo(fd, &si);
117 + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on,
118 + sizeof(on)) != 0) {
119 + syslog(LOG_ERR, "cannot set SO_REUSEADDR on %s",
125 - memcpy(taddr.addr.buf, sa, addrlen);
126 -#ifdef RPCBIND_DEBUG
129 - * for debugging print out our universal
137 - switch( sa->sa_family){
139 - sa_size = sizeof (struct sockaddr_in);
142 - sa_size = sizeof (struct sockaddr_in6);
145 - nb.len = nb.maxlen = sa_size;
146 - uaddr = taddr2uaddr(nconf, &nb);
147 - (void) fprintf(stderr,
148 - "rpcbind : my address is %s\n", uaddr);
149 - (void) free(uaddr);
152 - my_xprt = (SVCXPRT *)svc_tli_create(fd, nconf, &taddr,
153 - RPC_MAXDATASIZE, RPC_MAXDATASIZE);
154 - if (my_xprt == (SVCXPRT *)NULL) {
155 - syslog(LOG_ERR, "%s: could not create service",
162 - } else { /* NC_TPI_COTS */
163 - if ((strcmp(nconf->nc_netid, "local") != 0) &&
164 - (strcmp(nconf->nc_netid, "unix") != 0)) {
165 - if ((aicode = getaddrinfo(NULL, servname, &hints, &res))!= 0) {
166 - if ((aicode = getaddrinfo(NULL, "portmapper", &hints, &res))!= 0) {
167 - printf("cannot get local address for %s: %s", nconf->nc_netid, gai_strerror(aicode));
169 - "cannot get local address for %s: %s",
170 - nconf->nc_netid, gai_strerror(aicode));
175 - addrlen = res->ai_addrlen;
176 - sa = (struct sockaddr *)res->ai_addr;
178 - oldmask = umask(S_IXUSR|S_IXGRP|S_IXOTH);
179 - __rpc_fd2sockinfo(fd, &si);
180 - if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on,
181 - sizeof(on)) != 0) {
182 - syslog(LOG_ERR, "cannot set SO_REUSEADDR on %s",
188 if (bind(fd, sa, addrlen) < 0) {
189 - syslog(LOG_ERR, "cannot bind %s: %m", nconf->nc_netid);
190 + syslog(LOG_ERR, "cannot bind %s on %s: %m",
191 + (hosts && hosts[nhostsbak]) ? hosts[nhostsbak] : "*",
200 (void) umask(oldmask);
202 /* Copy the address */
203 @@ -527,7 +447,7 @@ init_transport(struct netconfig *nconf)
204 /* for debugging print out our universal address */
211 switch( sa->sa_family){
212 @@ -546,7 +466,8 @@ init_transport(struct netconfig *nconf)
216 - listen(fd, SOMAXCONN);
217 + if (nconf->nc_semantics != NC_TPI_CLTS)
218 + listen(fd, SOMAXCONN);
220 my_xprt = (SVCXPRT *)svc_tli_create(fd, nconf, &taddr, RPC_MAXDATASIZE, RPC_MAXDATASIZE);
221 if (my_xprt == (SVCXPRT *)NULL) {
222 @@ -555,6 +476,8 @@ init_transport(struct netconfig *nconf)
231 diff --git a/man/rpcbind.8 b/man/rpcbind.8
232 index c5b8fb7..aa53a25 100644
235 @@ -85,7 +85,7 @@ checks are shown in detail.
237 Do not fork and become a background process.
239 -Specify specific IP addresses to bind to for UDP requests.
240 +Specify specific IP addresses to bind to for requests.
242 may be specified multiple times and is typically necessary when running
243 on a multi-homed host.