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