xref: /netbsd-src/lib/libc/rpc/clnt_bcast.c (revision c5e820cae412164fcbee52f470436200af5358ea)
1 /*	$NetBSD: clnt_bcast.c,v 1.23 2012/03/13 21:13:44 christos Exp $	*/
2 
3 /*
4  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5  * unrestricted use provided that this legend is included on all tape
6  * media and as a part of the software program in whole or part.  Users
7  * may copy or modify Sun RPC without charge, but are not authorized
8  * to license or distribute it to anyone else except as part of a product or
9  * program developed by the user.
10  *
11  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14  *
15  * Sun RPC is provided with no support and without any obligation on the
16  * part of Sun Microsystems, Inc. to assist in its use, correction,
17  * modification or enhancement.
18  *
19  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21  * OR ANY PART THEREOF.
22  *
23  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24  * or profits or other special, indirect and consequential damages, even if
25  * Sun has been advised of the possibility of such damages.
26  *
27  * Sun Microsystems, Inc.
28  * 2550 Garcia Avenue
29  * Mountain View, California  94043
30  */
31 /*
32  * Copyright (c) 1986-1991 by Sun Microsystems Inc.
33  */
34 
35 /* #ident	"@(#)clnt_bcast.c	1.18	94/05/03 SMI" */
36 
37 #include <sys/cdefs.h>
38 #if defined(LIBC_SCCS) && !defined(lint)
39 #if 0
40 static char sccsid[] = "@(#)clnt_bcast.c 1.15 89/04/21 Copyr 1988 Sun Micro";
41 #else
42 __RCSID("$NetBSD: clnt_bcast.c,v 1.23 2012/03/13 21:13:44 christos Exp $");
43 #endif
44 #endif
45 
46 /*
47  * clnt_bcast.c
48  * Client interface to broadcast service.
49  *
50  * Copyright (C) 1988, Sun Microsystems, Inc.
51  *
52  * The following is kludged-up support for simple rpc broadcasts.
53  * Someday a large, complicated system will replace these routines.
54  */
55 
56 #include "namespace.h"
57 #include <sys/types.h>
58 #include <sys/socket.h>
59 #include <sys/queue.h>
60 #include <net/if.h>
61 #include <netinet/in.h>
62 #include <ifaddrs.h>
63 #include <sys/poll.h>
64 #include <rpc/rpc.h>
65 #ifdef PORTMAP
66 #include <rpc/pmap_prot.h>
67 #include <rpc/pmap_clnt.h>
68 #include <rpc/pmap_rmt.h>
69 #endif
70 #include <rpc/nettype.h>
71 #include <arpa/inet.h>
72 #ifdef RPC_DEBUG
73 #include <stdio.h>
74 #endif
75 #include <assert.h>
76 #include <errno.h>
77 #include <stdlib.h>
78 #include <unistd.h>
79 #include <netdb.h>
80 #include <err.h>
81 #include <string.h>
82 
83 #include "rpc_internal.h"
84 
85 #define	MAXBCAST 20	/* Max no of broadcasting transports */
86 #define	INITTIME 4000	/* Time to wait initially */
87 #define	WAITTIME 8000	/* Maximum time to wait */
88 
89 /*
90  * If nettype is NULL, it broadcasts on all the available
91  * datagram_n transports. May potentially lead to broadacst storms
92  * and hence should be used with caution, care and courage.
93  *
94  * The current parameter xdr packet size is limited by the max tsdu
95  * size of the transport. If the max tsdu size of any transport is
96  * smaller than the parameter xdr packet, then broadcast is not
97  * sent on that transport.
98  *
99  * Also, the packet size should be less the packet size of
100  * the data link layer (for ethernet it is 1400 bytes).  There is
101  * no easy way to find out the max size of the data link layer and
102  * we are assuming that the args would be smaller than that.
103  *
104  * The result size has to be smaller than the transport tsdu size.
105  *
106  * If PORTMAP has been defined, we send two packets for UDP, one for
107  * rpcbind and one for portmap. For those machines which support
108  * both rpcbind and portmap, it will cause them to reply twice, and
109  * also here it will get two responses ... inefficient and clumsy.
110  */
111 
112 #ifdef __weak_alias
113 __weak_alias(rpc_broadcast_exp,_rpc_broadcast_exp)
114 __weak_alias(rpc_broadcast,_rpc_broadcast)
115 #endif
116 
117 struct broadif {
118 	int index;
119 	struct sockaddr_storage broadaddr;
120 	TAILQ_ENTRY(broadif) link;
121 };
122 
123 typedef TAILQ_HEAD(, broadif) broadlist_t;
124 
125 int __rpc_getbroadifs __P((int, int, int, broadlist_t *));
126 void __rpc_freebroadifs __P((broadlist_t *));
127 int __rpc_broadenable __P((int, int, struct broadif *));
128 
129 int __rpc_lowvers = 0;
130 
131 int
132 __rpc_getbroadifs(int af, int proto, int socktype, broadlist_t *list)
133 {
134 	int count = 0;
135 	struct broadif *bip;
136 	struct ifaddrs *ifap, *ifp;
137 #ifdef INET6
138 	struct sockaddr_in6 *sin6;
139 #endif
140 	struct sockaddr_in *gbsin;
141 	struct addrinfo hints, *res;
142 
143 	_DIAGASSERT(list != NULL);
144 
145 	if (getifaddrs(&ifp) < 0)
146 		return 0;
147 
148 	memset(&hints, 0, sizeof hints);
149 
150 	hints.ai_family = af;
151 	hints.ai_protocol = proto;
152 	hints.ai_socktype = socktype;
153 
154 	if (getaddrinfo(NULL, "sunrpc", &hints, &res) != 0) {
155 		freeifaddrs(ifp);
156 		return 0;
157 	}
158 
159 	for (ifap = ifp; ifap != NULL; ifap = ifap->ifa_next) {
160 		if (ifap->ifa_addr->sa_family != af ||
161 		    !(ifap->ifa_flags & IFF_UP))
162 			continue;
163 		bip = malloc(sizeof(*bip));
164 		if (bip == NULL)
165 			break;
166 		bip->index = if_nametoindex(ifap->ifa_name);
167 		if (
168 #ifdef INET6
169 		    af != AF_INET6 &&
170 #endif
171 		    (ifap->ifa_flags & IFF_BROADCAST) &&
172 		    ifap->ifa_broadaddr) {
173 			memcpy(&bip->broadaddr, ifap->ifa_broadaddr,
174 			    (size_t)ifap->ifa_broadaddr->sa_len);
175 			gbsin = (struct sockaddr_in *)(void *)&bip->broadaddr;
176 			gbsin->sin_port =
177 			    ((struct sockaddr_in *)
178 			    (void *)res->ai_addr)->sin_port;
179 		} else
180 #ifdef INET6
181 		if (af == AF_INET6 && (ifap->ifa_flags & IFF_MULTICAST)) {
182 			sin6 = (struct sockaddr_in6 *)(void *)&bip->broadaddr;
183 			inet_pton(af, RPCB_MULTICAST_ADDR, &sin6->sin6_addr);
184 			sin6->sin6_family = af;
185 			sin6->sin6_len = sizeof *sin6;
186 			sin6->sin6_port =
187 			    ((struct sockaddr_in6 *)
188 			    (void *)res->ai_addr)->sin6_port;
189 			sin6->sin6_scope_id = bip->index;
190 		} else
191 #endif
192 		{
193 			free(bip);
194 			continue;
195 		}
196 		TAILQ_INSERT_TAIL(list, bip, link);
197 		count++;
198 	}
199 	freeifaddrs(ifp);
200 	freeaddrinfo(res);
201 
202 	return count;
203 }
204 
205 void
206 __rpc_freebroadifs(broadlist_t *list)
207 {
208 	struct broadif *bip, *next;
209 
210 	_DIAGASSERT(list != NULL);
211 
212 	bip = TAILQ_FIRST(list);
213 
214 	while (bip != NULL) {
215 		next = TAILQ_NEXT(bip, link);
216 		free(bip);
217 		bip = next;
218 	}
219 }
220 
221 int
222 /*ARGSUSED*/
223 __rpc_broadenable(int af, int s, struct broadif *bip)
224 {
225 	int o = 1;
226 
227 #if 0
228 	_DIAGASSERT(bip != NULL);
229 
230 	if (af == AF_INET6) {
231 		fprintf(stderr, "set v6 multicast if to %d\n", bip->index);
232 		if (setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_IF, &bip->index,
233 		    sizeof bip->index) < 0)
234 			return -1;
235 	} else
236 #endif
237 		if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &o,
238 		    (socklen_t)sizeof(o)) == -1)
239 			return -1;
240 
241 	return 0;
242 }
243 
244 
245 enum clnt_stat
246 rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
247 	eachresult, inittime, waittime, nettype)
248 	rpcprog_t	prog;		/* program number */
249 	rpcvers_t	vers;		/* version number */
250 	rpcproc_t	proc;		/* procedure number */
251 	xdrproc_t	xargs;		/* xdr routine for args */
252 	const char *	argsp;		/* pointer to args */
253 	xdrproc_t	xresults;	/* xdr routine for results */
254 	caddr_t		resultsp;	/* pointer to results */
255 	resultproc_t	eachresult;	/* call with each result obtained */
256 	int 		inittime;	/* how long to wait initially */
257 	int 		waittime;	/* maximum time to wait */
258 	const char		*nettype;	/* transport type */
259 {
260 	enum clnt_stat	stat = RPC_SUCCESS; /* Return status */
261 	XDR 		xdr_stream; /* XDR stream */
262 	XDR 		*xdrs = &xdr_stream;
263 	struct rpc_msg	msg;	/* RPC message */
264 	char 		*outbuf = NULL;	/* Broadcast msg buffer */
265 	char		*inbuf = NULL; /* Reply buf */
266 	ssize_t		inlen;
267 	u_int 		maxbufsize = 0;
268 	AUTH 		*sys_auth = authunix_create_default();
269 	size_t		i;
270 	void		*handle;
271 	char		uaddress[1024];	/* A self imposed limit */
272 	char		*uaddrp = uaddress;
273 	int 		pmap_reply_flag; /* reply recvd from PORTMAP */
274 	/* An array of all the suitable broadcast transports */
275 	struct {
276 		int fd;		/* File descriptor */
277 		int af;
278 		int proto;
279 		struct netconfig *nconf; /* Netconfig structure */
280 		u_int asize;	/* Size of the addr buf */
281 		u_int dsize;	/* Size of the data buf */
282 		struct sockaddr_storage raddr; /* Remote address */
283 		broadlist_t nal;
284 	} fdlist[MAXBCAST];
285 	struct pollfd pfd[MAXBCAST];
286 	nfds_t fdlistno = 0;
287 	struct r_rpcb_rmtcallargs barg;	/* Remote arguments */
288 	struct r_rpcb_rmtcallres bres; /* Remote results */
289 	size_t outlen;
290 	struct netconfig *nconf;
291 	int msec;
292 	int pollretval;
293 	int fds_found;
294 	struct timespec ts;
295 
296 #ifdef PORTMAP
297 	size_t outlen_pmap = 0;
298 	u_long port;		/* Remote port number */
299 	int pmap_flag = 0;	/* UDP exists ? */
300 	char *outbuf_pmap = NULL;
301 	struct rmtcallargs barg_pmap;	/* Remote arguments */
302 	struct rmtcallres bres_pmap; /* Remote results */
303 	u_int udpbufsz = 0;
304 #endif				/* PORTMAP */
305 
306 	if (sys_auth == NULL) {
307 		return (RPC_SYSTEMERROR);
308 	}
309 	/*
310 	 * initialization: create a fd, a broadcast address, and send the
311 	 * request on the broadcast transport.
312 	 * Listen on all of them and on replies, call the user supplied
313 	 * function.
314 	 */
315 
316 	if (nettype == NULL)
317 		nettype = "datagram_n";
318 	if ((handle = __rpc_setconf(nettype)) == NULL) {
319 		AUTH_DESTROY(sys_auth);
320 		return (RPC_UNKNOWNPROTO);
321 	}
322 	while ((nconf = __rpc_getconf(handle)) != NULL) {
323 		int fd;
324 		struct __rpc_sockinfo si;
325 
326 		if (nconf->nc_semantics != NC_TPI_CLTS)
327 			continue;
328 		if (fdlistno >= MAXBCAST)
329 			break;	/* No more slots available */
330 		if (!__rpc_nconf2sockinfo(nconf, &si))
331 			continue;
332 
333 		TAILQ_INIT(&fdlist[fdlistno].nal);
334 		if (__rpc_getbroadifs(si.si_af, si.si_proto, si.si_socktype,
335 		    &fdlist[fdlistno].nal) == 0)
336 			continue;
337 
338 		fd = socket(si.si_af, si.si_socktype, si.si_proto);
339 		if (fd < 0) {
340 			stat = RPC_CANTSEND;
341 			continue;
342 		}
343 		fdlist[fdlistno].af = si.si_af;
344 		fdlist[fdlistno].proto = si.si_proto;
345 		fdlist[fdlistno].fd = fd;
346 		fdlist[fdlistno].nconf = nconf;
347 		fdlist[fdlistno].asize = __rpc_get_a_size(si.si_af);
348 		pfd[fdlistno].events = POLLIN | POLLPRI |
349 			POLLRDNORM | POLLRDBAND;
350 		pfd[fdlistno].fd = fdlist[fdlistno].fd = fd;
351 		fdlist[fdlistno].dsize = __rpc_get_t_size(si.si_af, si.si_proto,
352 							  0);
353 
354 		if (maxbufsize <= fdlist[fdlistno].dsize)
355 			maxbufsize = fdlist[fdlistno].dsize;
356 
357 #ifdef PORTMAP
358 		if (si.si_af == AF_INET && si.si_proto == IPPROTO_UDP) {
359 			udpbufsz = fdlist[fdlistno].dsize;
360 			if ((outbuf_pmap = malloc(udpbufsz)) == NULL) {
361 				close(fd);
362 				stat = RPC_SYSTEMERROR;
363 				goto done_broad;
364 			}
365 			pmap_flag = 1;
366 		}
367 #endif
368 		fdlistno++;
369 	}
370 
371 	if (fdlistno == 0) {
372 		if (stat == RPC_SUCCESS)
373 			stat = RPC_UNKNOWNPROTO;
374 		goto done_broad;
375 	}
376 	if (maxbufsize == 0) {
377 		if (stat == RPC_SUCCESS)
378 			stat = RPC_CANTSEND;
379 		goto done_broad;
380 	}
381 	inbuf = malloc(maxbufsize);
382 	outbuf = malloc(maxbufsize);
383 	if ((inbuf == NULL) || (outbuf == NULL)) {
384 		stat = RPC_SYSTEMERROR;
385 		goto done_broad;
386 	}
387 
388 	/* Serialize all the arguments which have to be sent */
389 	msg.rm_xid = __RPC_GETXID();
390 	msg.rm_direction = CALL;
391 	msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
392 	msg.rm_call.cb_prog = RPCBPROG;
393 	msg.rm_call.cb_vers = RPCBVERS;
394 	msg.rm_call.cb_proc = RPCBPROC_CALLIT;
395 	barg.prog = prog;
396 	barg.vers = vers;
397 	barg.proc = proc;
398 	barg.args.args_val = argsp;
399 	barg.xdr_args = xargs;
400 	bres.addr = uaddrp;
401 	bres.results.results_val = resultsp;
402 	bres.xdr_res = xresults;
403 	msg.rm_call.cb_cred = sys_auth->ah_cred;
404 	msg.rm_call.cb_verf = sys_auth->ah_verf;
405 	xdrmem_create(xdrs, outbuf, maxbufsize, XDR_ENCODE);
406 	if ((!xdr_callmsg(xdrs, &msg)) ||
407 	    (!xdr_rpcb_rmtcallargs(xdrs,
408 	    (struct rpcb_rmtcallargs *)(void *)&barg))) {
409 		stat = RPC_CANTENCODEARGS;
410 		goto done_broad;
411 	}
412 	outlen = xdr_getpos(xdrs);
413 	xdr_destroy(xdrs);
414 
415 #ifdef PORTMAP
416 	/* Prepare the packet for version 2 PORTMAP */
417 	if (pmap_flag) {
418 		msg.rm_xid++;	/* One way to distinguish */
419 		msg.rm_call.cb_prog = PMAPPROG;
420 		msg.rm_call.cb_vers = PMAPVERS;
421 		msg.rm_call.cb_proc = PMAPPROC_CALLIT;
422 		barg_pmap.prog = prog;
423 		barg_pmap.vers = vers;
424 		barg_pmap.proc = proc;
425 		barg_pmap.args_ptr = argsp;
426 		barg_pmap.xdr_args = xargs;
427 		bres_pmap.port_ptr = &port;
428 		bres_pmap.xdr_results = xresults;
429 		bres_pmap.results_ptr = resultsp;
430 		xdrmem_create(xdrs, outbuf_pmap, udpbufsz, XDR_ENCODE);
431 		if ((! xdr_callmsg(xdrs, &msg)) ||
432 		    (! xdr_rmtcall_args(xdrs, &barg_pmap))) {
433 			stat = RPC_CANTENCODEARGS;
434 			goto done_broad;
435 		}
436 		outlen_pmap = xdr_getpos(xdrs);
437 		xdr_destroy(xdrs);
438 	}
439 #endif				/* PORTMAP */
440 
441 	/*
442 	 * Basic loop: broadcast the packets to transports which
443 	 * support data packets of size such that one can encode
444 	 * all the arguments.
445 	 * Wait a while for response(s).
446 	 * The response timeout grows larger per iteration.
447 	 */
448 	for (msec = inittime; msec <= waittime; msec += msec) {
449 		struct broadif *bip;
450 
451 		/* Broadcast all the packets now */
452 		for (i = 0; i < fdlistno; i++) {
453 			if (fdlist[i].dsize < outlen) {
454 				stat = RPC_CANTSEND;
455 				continue;
456 			}
457 			for (bip = TAILQ_FIRST(&fdlist[i].nal); bip != NULL;
458 			     bip = TAILQ_NEXT(bip, link)) {
459 				void *addr;
460 
461 				addr = &bip->broadaddr;
462 
463 				__rpc_broadenable(fdlist[i].af, fdlist[i].fd,
464 				    bip);
465 
466 				/*
467 				 * Only use version 3 if lowvers is not set
468 				 */
469 
470 				if (!__rpc_lowvers)
471 					if ((size_t)sendto(fdlist[i].fd, outbuf,
472 					    outlen, 0, (struct sockaddr*)addr,
473 					    (socklen_t)fdlist[i].asize) !=
474 					    outlen) {
475 						warn("clnt_bcast: cannot send"
476 						      " broadcast packet");
477 						stat = RPC_CANTSEND;
478 						continue;
479 					}
480 #ifdef RPC_DEBUG
481 				if (!__rpc_lowvers)
482 					fprintf(stderr, "Broadcast packet sent "
483 						"for %s\n",
484 						 fdlist[i].nconf->nc_netid);
485 #endif
486 #ifdef PORTMAP
487 				/*
488 				 * Send the version 2 packet also
489 				 * for UDP/IP
490 				 */
491 				if (pmap_flag &&
492 				    fdlist[i].proto == IPPROTO_UDP) {
493 					if ((size_t)sendto(fdlist[i].fd,
494 					    outbuf_pmap, outlen_pmap, 0, addr,
495 					    (socklen_t)fdlist[i].asize) !=
496 						outlen_pmap) {
497 						warnx("clnt_bcast: "
498 						    "Cannot send "
499 						    "broadcast packet");
500 						stat = RPC_CANTSEND;
501 						continue;
502 					}
503 				}
504 #ifdef RPC_DEBUG
505 				fprintf(stderr, "PMAP Broadcast packet "
506 					"sent for %s\n",
507 					fdlist[i].nconf->nc_netid);
508 #endif
509 #endif				/* PORTMAP */
510 			}
511 			/* End for sending all packets on this transport */
512 		}	/* End for sending on all transports */
513 
514 		if (eachresult == NULL) {
515 			stat = RPC_SUCCESS;
516 			goto done_broad;
517 		}
518 
519 		/*
520 		 * Get all the replies from these broadcast requests
521 		 */
522 	recv_again:
523 		ts.tv_sec = msec / 1000;
524 		ts.tv_nsec = (msec % 1000) * 1000000;
525 
526 		switch (pollretval = pollts(pfd, fdlistno, &ts, NULL)) {
527 		case 0:		/* timed out */
528 			stat = RPC_TIMEDOUT;
529 			continue;
530 		case -1:	/* some kind of error - we ignore it */
531 			goto recv_again;
532 		}		/* end of poll results switch */
533 
534 		for (i = fds_found = 0;
535 		     i < fdlistno && fds_found < pollretval; i++) {
536 			bool_t done = FALSE;
537 
538 			if (pfd[i].revents == 0)
539 				continue;
540 			else if (pfd[i].revents & POLLNVAL) {
541 				/*
542 				 * Something bad has happened to this descri-
543 				 * ptor. We can cause pollts() to ignore
544 				 * it simply by using a negative fd.  We do that
545 				 * rather than compacting the pfd[] and fdlist[]
546 				 * arrays.
547 				 */
548 				pfd[i].fd = -1;
549 				fds_found++;
550 				continue;
551 			} else
552 				fds_found++;
553 #ifdef RPC_DEBUG
554 			fprintf(stderr, "response for %s\n",
555 				fdlist[i].nconf->nc_netid);
556 #endif
557 		try_again:
558 			inlen = recvfrom(fdlist[i].fd, inbuf, fdlist[i].dsize,
559 			    0, (struct sockaddr *)(void *)&fdlist[i].raddr,
560 			    &fdlist[i].asize);
561 			if (inlen < 0) {
562 				if (errno == EINTR)
563 					goto try_again;
564 				warnx("clnt_bcast: Cannot receive reply to "
565 					"broadcast");
566 				stat = RPC_CANTRECV;
567 				continue;
568 			}
569 			if (inlen < (ssize_t)sizeof(u_int32_t))
570 				continue; /* Drop that and go ahead */
571 			/*
572 			 * see if reply transaction id matches sent id.
573 			 * If so, decode the results. If return id is xid + 1
574 			 * it was a PORTMAP reply
575 			 */
576 			if (*((u_int32_t *)(void *)(inbuf)) ==
577 			    *((u_int32_t *)(void *)(outbuf))) {
578 				pmap_reply_flag = 0;
579 				msg.acpted_rply.ar_verf = _null_auth;
580 				msg.acpted_rply.ar_results.where =
581 					(caddr_t)(void *)&bres;
582 				msg.acpted_rply.ar_results.proc =
583 					(xdrproc_t)xdr_rpcb_rmtcallres;
584 #ifdef PORTMAP
585 			} else if (pmap_flag &&
586 				*((u_int32_t *)(void *)(inbuf)) ==
587 				*((u_int32_t *)(void *)(outbuf_pmap))) {
588 				pmap_reply_flag = 1;
589 				msg.acpted_rply.ar_verf = _null_auth;
590 				msg.acpted_rply.ar_results.where =
591 					(caddr_t)(void *)&bres_pmap;
592 				msg.acpted_rply.ar_results.proc =
593 					(xdrproc_t)xdr_rmtcallres;
594 #endif				/* PORTMAP */
595 			} else
596 				continue;
597 			xdrmem_create(xdrs, inbuf, (u_int)inlen, XDR_DECODE);
598 			if (xdr_replymsg(xdrs, &msg)) {
599 				if ((msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
600 				    (msg.acpted_rply.ar_stat == SUCCESS)) {
601 					struct netbuf taddr, *np;
602 					struct sockaddr_in *bsin;
603 
604 #ifdef PORTMAP
605 					if (pmap_flag && pmap_reply_flag) {
606 						bsin = (struct sockaddr_in *)
607 						    (void *)&fdlist[i].raddr;
608 						bsin->sin_port =
609 						    htons((u_short)port);
610 						taddr.len = taddr.maxlen =
611 						    fdlist[i].raddr.ss_len;
612 						taddr.buf = &fdlist[i].raddr;
613 						done = (*eachresult)(resultsp,
614 						    &taddr, fdlist[i].nconf);
615 					} else {
616 #endif
617 #ifdef RPC_DEBUG
618 						fprintf(stderr, "uaddr %s\n",
619 						    uaddrp);
620 #endif
621 						np = uaddr2taddr(
622 						    fdlist[i].nconf, uaddrp);
623 						done = (*eachresult)(resultsp,
624 						    np, fdlist[i].nconf);
625 						free(np);
626 #ifdef PORTMAP
627 					}
628 #endif
629 				}
630 				/* otherwise, we just ignore the errors ... */
631 			}
632 			/* else some kind of deserialization problem ... */
633 
634 			xdrs->x_op = XDR_FREE;
635 			msg.acpted_rply.ar_results.proc = (xdrproc_t) xdr_void;
636 			(void) xdr_replymsg(xdrs, &msg);
637 			(void) (*xresults)(xdrs, resultsp);
638 			XDR_DESTROY(xdrs);
639 			if (done) {
640 				stat = RPC_SUCCESS;
641 				goto done_broad;
642 			} else {
643 				goto recv_again;
644 			}
645 		}		/* The recv for loop */
646 	}			/* The giant for loop */
647 
648 done_broad:
649 	if (inbuf)
650 		(void) free(inbuf);
651 	if (outbuf)
652 		(void) free(outbuf);
653 #ifdef PORTMAP
654 	if (outbuf_pmap)
655 		(void) free(outbuf_pmap);
656 #endif
657 	for (i = 0; i < fdlistno; i++) {
658 		(void) close(fdlist[i].fd);
659 		__rpc_freebroadifs(&fdlist[i].nal);
660 	}
661 	AUTH_DESTROY(sys_auth);
662 	(void) __rpc_endconf(handle);
663 
664 	return (stat);
665 }
666 
667 
668 enum clnt_stat
669 rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
670 			eachresult, nettype)
671 	rpcprog_t	prog;		/* program number */
672 	rpcvers_t	vers;		/* version number */
673 	rpcproc_t	proc;		/* procedure number */
674 	xdrproc_t	xargs;		/* xdr routine for args */
675 	const char *	argsp;		/* pointer to args */
676 	xdrproc_t	xresults;	/* xdr routine for results */
677 	caddr_t		resultsp;	/* pointer to results */
678 	resultproc_t	eachresult;	/* call with each result obtained */
679 	const char		*nettype;	/* transport type */
680 {
681 	enum clnt_stat	dummy;
682 
683 	dummy = rpc_broadcast_exp(prog, vers, proc, xargs, argsp,
684 		xresults, resultsp, eachresult,
685 		INITTIME, WAITTIME, nettype);
686 	return (dummy);
687 }
688