xref: /freebsd/lib/libc/rpc/clnt_bcast.c (revision 8fc257994d0ce2396196d7a06d50d20c8015f4b7)
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 #if defined(LIBC_SCCS) && !defined(lint)
36 #ident	"@(#)clnt_bcast.c	1.18	94/05/03 SMI"
37 static char sccsid[] = "@(#)clnt_bcast.c 1.15 89/04/21 Copyr 1988 Sun Micro";
38 #endif
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
41 
42 
43 /*
44  * clnt_bcast.c
45  * Client interface to broadcast service.
46  *
47  * Copyright (C) 1988, Sun Microsystems, Inc.
48  *
49  * The following is kludged-up support for simple rpc broadcasts.
50  * Someday a large, complicated system will replace these routines.
51  */
52 
53 #include "namespace.h"
54 #include <sys/types.h>
55 #include <sys/socket.h>
56 #include <sys/queue.h>
57 #include <net/if.h>
58 #include <netinet/in.h>
59 #include <ifaddrs.h>
60 #include <sys/poll.h>
61 #include <rpc/rpc.h>
62 #ifdef PORTMAP
63 #include <rpc/pmap_prot.h>
64 #include <rpc/pmap_clnt.h>
65 #include <rpc/pmap_rmt.h>
66 #endif				/* PORTMAP */
67 #include <rpc/nettype.h>
68 #include <arpa/inet.h>
69 #ifdef RPC_DEBUG
70 #include <stdio.h>
71 #endif
72 #include <errno.h>
73 #include <stdlib.h>
74 #include <unistd.h>
75 #include <netdb.h>
76 #include <err.h>
77 #include <string.h>
78 #include "un-namespace.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 struct broadif {
110 	int index;
111 	struct sockaddr_storage broadaddr;
112 	TAILQ_ENTRY(broadif) link;
113 };
114 
115 typedef TAILQ_HEAD(, broadif) broadlist_t;
116 
117 int __rpc_getbroadifs(int, int, int, broadlist_t *);
118 void __rpc_freebroadifs(broadlist_t *);
119 int __rpc_broadenable(int, int, struct broadif *);
120 
121 int __rpc_lowvers = 0;
122 
123 int
124 __rpc_getbroadifs(int af, int proto, int socktype, broadlist_t *list)
125 {
126 	int count = 0;
127 	struct broadif *bip;
128 	struct ifaddrs *ifap, *ifp;
129 #ifdef INET6
130 	struct sockaddr_in6 *sin6;
131 #endif
132 	struct sockaddr_in *sin;
133 	struct addrinfo hints, *res;
134 
135 	if (getifaddrs(&ifp) < 0)
136 		return 0;
137 
138 	memset(&hints, 0, sizeof hints);
139 
140 	hints.ai_family = af;
141 	hints.ai_protocol = proto;
142 	hints.ai_socktype = socktype;
143 
144 	if (getaddrinfo(NULL, "sunrpc", &hints, &res) != 0) {
145 		freeifaddrs(ifp);
146 		return 0;
147 	}
148 
149 	for (ifap = ifp; ifap != NULL; ifap = ifap->ifa_next) {
150 		if (ifap->ifa_addr->sa_family != af ||
151 		    !(ifap->ifa_flags & IFF_UP))
152 			continue;
153 		bip = (struct broadif *)malloc(sizeof *bip);
154 		if (bip == NULL)
155 			break;
156 		bip->index = if_nametoindex(ifap->ifa_name);
157 		if (
158 #ifdef INET6
159 		af != AF_INET6 &&
160 #endif
161 		(ifap->ifa_flags & IFF_BROADCAST) &&
162 		 ifap->ifa_broadaddr) {
163 			memcpy(&bip->broadaddr, ifap->ifa_broadaddr,
164 			    (size_t)ifap->ifa_broadaddr->sa_len);
165 			sin = (struct sockaddr_in *)(void *)&bip->broadaddr;
166 			sin->sin_port =
167 			    ((struct sockaddr_in *)
168 			    (void *)res->ai_addr)->sin_port;
169 		} else
170 #ifdef INET6
171 		if (af == AF_INET6 && (ifap->ifa_flags & IFF_MULTICAST)) {
172 			sin6 = (struct sockaddr_in6 *)(void *)&bip->broadaddr;
173 			inet_pton(af, RPCB_MULTICAST_ADDR, &sin6->sin6_addr);
174 			sin6->sin6_family = af;
175 			sin6->sin6_len = sizeof *sin6;
176 			sin6->sin6_port =
177 			    ((struct sockaddr_in6 *)
178 			    (void *)res->ai_addr)->sin6_port;
179 			sin6->sin6_scope_id = bip->index;
180 		} else
181 #endif
182 		{
183 			free(bip);
184 			continue;
185 		}
186 		TAILQ_INSERT_TAIL(list, bip, link);
187 		count++;
188 	}
189 	freeifaddrs(ifp);
190 	freeaddrinfo(res);
191 
192 	return count;
193 }
194 
195 void
196 __rpc_freebroadifs(broadlist_t *list)
197 {
198 	struct broadif *bip, *next;
199 
200 	bip = TAILQ_FIRST(list);
201 
202 	while (bip != NULL) {
203 		next = TAILQ_NEXT(bip, link);
204 		free(bip);
205 		bip = next;
206 	}
207 }
208 
209 int
210 /*ARGSUSED*/
211 __rpc_broadenable(int af, int s, struct broadif *bip)
212 {
213 	int o = 1;
214 
215 #if 0
216 	if (af == AF_INET6) {
217 		fprintf(stderr, "set v6 multicast if to %d\n", bip->index);
218 		if (_setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_IF, &bip->index,
219 		    sizeof bip->index) < 0)
220 			return -1;
221 	} else
222 #endif
223 		if (_setsockopt(s, SOL_SOCKET, SO_BROADCAST, &o, sizeof o) < 0)
224 			return -1;
225 
226 	return 0;
227 }
228 
229 
230 enum clnt_stat
231 rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
232 	eachresult, inittime, waittime, nettype)
233 	rpcprog_t	prog;		/* program number */
234 	rpcvers_t	vers;		/* version number */
235 	rpcproc_t	proc;		/* procedure number */
236 	xdrproc_t	xargs;		/* xdr routine for args */
237 	caddr_t		argsp;		/* pointer to args */
238 	xdrproc_t	xresults;	/* xdr routine for results */
239 	caddr_t		resultsp;	/* pointer to results */
240 	resultproc_t	eachresult;	/* call with each result obtained */
241 	int 		inittime;	/* how long to wait initially */
242 	int 		waittime;	/* maximum time to wait */
243 	const char		*nettype;	/* transport type */
244 {
245 	enum clnt_stat	stat = RPC_SUCCESS; /* Return status */
246 	XDR 		xdr_stream; /* XDR stream */
247 	XDR 		*xdrs = &xdr_stream;
248 	struct rpc_msg	msg;	/* RPC message */
249 	struct timeval	t;
250 	char 		*outbuf = NULL;	/* Broadcast msg buffer */
251 	char		*inbuf = NULL; /* Reply buf */
252 	int		inlen;
253 	u_int 		maxbufsize = 0;
254 	AUTH 		*sys_auth = authunix_create_default();
255 	int		i;
256 	void		*handle;
257 	char		uaddress[1024];	/* A self imposed limit */
258 	char		*uaddrp = uaddress;
259 	int 		pmap_reply_flag; /* reply recvd from PORTMAP */
260 	/* An array of all the suitable broadcast transports */
261 	struct {
262 		int fd;		/* File descriptor */
263 		int af;
264 		int proto;
265 		struct netconfig *nconf; /* Netconfig structure */
266 		u_int asize;	/* Size of the addr buf */
267 		u_int dsize;	/* Size of the data buf */
268 		struct sockaddr_storage raddr; /* Remote address */
269 		broadlist_t nal;
270 	} fdlist[MAXBCAST];
271 	struct pollfd pfd[MAXBCAST];
272 	size_t fdlistno = 0;
273 	struct r_rpcb_rmtcallargs barg;	/* Remote arguments */
274 	struct r_rpcb_rmtcallres bres; /* Remote results */
275 	size_t outlen;
276 	struct netconfig *nconf;
277 	int msec;
278 	int pollretval;
279 	int fds_found;
280 
281 #ifdef PORTMAP
282 	size_t outlen_pmap = 0;
283 	u_long port;		/* Remote port number */
284 	int pmap_flag = 0;	/* UDP exists ? */
285 	char *outbuf_pmap = NULL;
286 	struct rmtcallargs barg_pmap;	/* Remote arguments */
287 	struct rmtcallres bres_pmap; /* Remote results */
288 	u_int udpbufsz = 0;
289 #endif				/* PORTMAP */
290 
291 	if (sys_auth == NULL) {
292 		return (RPC_SYSTEMERROR);
293 	}
294 	/*
295 	 * initialization: create a fd, a broadcast address, and send the
296 	 * request on the broadcast transport.
297 	 * Listen on all of them and on replies, call the user supplied
298 	 * function.
299 	 */
300 
301 	if (nettype == NULL)
302 		nettype = "datagram_n";
303 	if ((handle = __rpc_setconf(nettype)) == NULL) {
304 		AUTH_DESTROY(sys_auth);
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				/* PORTMAP */
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 (pmap_flag &&
481 				    fdlist[i].proto == IPPROTO_UDP) {
482 					if (_sendto(fdlist[i].fd, outbuf_pmap,
483 					    outlen_pmap, 0, addr,
484 					    (size_t)fdlist[i].asize) !=
485 						outlen_pmap) {
486 						warnx("clnt_bcast: "
487 						    "Cannot send broadcast packet");
488 						stat = RPC_CANTSEND;
489 						continue;
490 					}
491 				}
492 #ifdef RPC_DEBUG
493 				fprintf(stderr, "PMAP Broadcast packet "
494 					"sent for %s\n",
495 					fdlist[i].nconf->nc_netid);
496 #endif
497 #endif				/* PORTMAP */
498 			}
499 			/* End for sending all packets on this transport */
500 		}	/* End for sending on all transports */
501 
502 		if (eachresult == NULL) {
503 			stat = RPC_SUCCESS;
504 			goto done_broad;
505 		}
506 
507 		/*
508 		 * Get all the replies from these broadcast requests
509 		 */
510 	recv_again:
511 
512 		switch (pollretval = _poll(pfd, fdlistno, msec)) {
513 		case 0:		/* timed out */
514 			stat = RPC_TIMEDOUT;
515 			continue;
516 		case -1:	/* some kind of error - we ignore it */
517 			goto recv_again;
518 		}		/* end of poll results switch */
519 
520 		for (i = fds_found = 0;
521 		     i < fdlistno && fds_found < pollretval; i++) {
522 			bool_t done = FALSE;
523 
524 			if (pfd[i].revents == 0)
525 				continue;
526 			else if (pfd[i].revents & POLLNVAL) {
527 				/*
528 				 * Something bad has happened to this descri-
529 				 * ptor. We can cause _poll() to ignore
530 				 * it simply by using a negative fd.  We do that
531 				 * rather than compacting the pfd[] and fdlist[]
532 				 * arrays.
533 				 */
534 				pfd[i].fd = -1;
535 				fds_found++;
536 				continue;
537 			} else
538 				fds_found++;
539 #ifdef RPC_DEBUG
540 			fprintf(stderr, "response for %s\n",
541 				fdlist[i].nconf->nc_netid);
542 #endif
543 		try_again:
544 			inlen = _recvfrom(fdlist[i].fd, inbuf, fdlist[i].dsize,
545 			    0, (struct sockaddr *)(void *)&fdlist[i].raddr,
546 			    &fdlist[i].asize);
547 			if (inlen < 0) {
548 				if (errno == EINTR)
549 					goto try_again;
550 				warnx("clnt_bcast: Cannot receive reply to "
551 					"broadcast");
552 				stat = RPC_CANTRECV;
553 				continue;
554 			}
555 			if (inlen < sizeof (u_int32_t))
556 				continue; /* Drop that and go ahead */
557 			/*
558 			 * see if reply transaction id matches sent id.
559 			 * If so, decode the results. If return id is xid + 1
560 			 * it was a PORTMAP reply
561 			 */
562 			if (*((u_int32_t *)(void *)(inbuf)) ==
563 			    *((u_int32_t *)(void *)(outbuf))) {
564 				pmap_reply_flag = 0;
565 				msg.acpted_rply.ar_verf = _null_auth;
566 				msg.acpted_rply.ar_results.where =
567 					(caddr_t)(void *)&bres;
568 				msg.acpted_rply.ar_results.proc =
569 					(xdrproc_t)xdr_rpcb_rmtcallres;
570 #ifdef PORTMAP
571 			} else if (pmap_flag &&
572 				*((u_int32_t *)(void *)(inbuf)) ==
573 				*((u_int32_t *)(void *)(outbuf_pmap))) {
574 				pmap_reply_flag = 1;
575 				msg.acpted_rply.ar_verf = _null_auth;
576 				msg.acpted_rply.ar_results.where =
577 					(caddr_t)(void *)&bres_pmap;
578 				msg.acpted_rply.ar_results.proc =
579 					(xdrproc_t)xdr_rmtcallres;
580 #endif				/* PORTMAP */
581 			} else
582 				continue;
583 			xdrmem_create(xdrs, inbuf, (u_int)inlen, XDR_DECODE);
584 			if (xdr_replymsg(xdrs, &msg)) {
585 				if ((msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
586 				    (msg.acpted_rply.ar_stat == SUCCESS)) {
587 					struct netbuf taddr, *np;
588 					struct sockaddr_in *sin;
589 
590 #ifdef PORTMAP
591 					if (pmap_flag && pmap_reply_flag) {
592 						sin = (struct sockaddr_in *)
593 						    (void *)&fdlist[i].raddr;
594 						sin->sin_port =
595 						    htons((u_short)port);
596 						taddr.len = taddr.maxlen =
597 						    fdlist[i].raddr.ss_len;
598 						taddr.buf = &fdlist[i].raddr;
599 						done = (*eachresult)(resultsp,
600 						    &taddr, fdlist[i].nconf);
601 					} else {
602 #endif				/* PORTMAP */
603 #ifdef RPC_DEBUG
604 						fprintf(stderr, "uaddr %s\n",
605 						    uaddrp);
606 #endif
607 						np = uaddr2taddr(
608 						    fdlist[i].nconf, uaddrp);
609 						done = (*eachresult)(resultsp,
610 						    np, fdlist[i].nconf);
611 						free(np);
612 #ifdef PORTMAP
613 					}
614 #endif				/* PORTMAP */
615 				}
616 				/* otherwise, we just ignore the errors ... */
617 			}
618 			/* else some kind of deserialization problem ... */
619 
620 			xdrs->x_op = XDR_FREE;
621 			msg.acpted_rply.ar_results.proc = (xdrproc_t) xdr_void;
622 			(void) xdr_replymsg(xdrs, &msg);
623 			(void) (*xresults)(xdrs, resultsp);
624 			XDR_DESTROY(xdrs);
625 			if (done) {
626 				stat = RPC_SUCCESS;
627 				goto done_broad;
628 			} else {
629 				goto recv_again;
630 			}
631 		}		/* The recv for loop */
632 	}			/* The giant for loop */
633 
634 done_broad:
635 	if (inbuf)
636 		(void) free(inbuf);
637 	if (outbuf)
638 		(void) free(outbuf);
639 #ifdef PORTMAP
640 	if (outbuf_pmap)
641 		(void) free(outbuf_pmap);
642 #endif				/* PORTMAP */
643 	for (i = 0; i < fdlistno; i++) {
644 		(void)_close(fdlist[i].fd);
645 		__rpc_freebroadifs(&fdlist[i].nal);
646 	}
647 	AUTH_DESTROY(sys_auth);
648 	(void) __rpc_endconf(handle);
649 
650 	return (stat);
651 }
652 
653 
654 enum clnt_stat
655 rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
656 			eachresult, nettype)
657 	rpcprog_t	prog;		/* program number */
658 	rpcvers_t	vers;		/* version number */
659 	rpcproc_t	proc;		/* procedure number */
660 	xdrproc_t	xargs;		/* xdr routine for args */
661 	caddr_t		argsp;		/* pointer to args */
662 	xdrproc_t	xresults;	/* xdr routine for results */
663 	caddr_t		resultsp;	/* pointer to results */
664 	resultproc_t	eachresult;	/* call with each result obtained */
665 	const char		*nettype;	/* transport type */
666 {
667 	enum clnt_stat	dummy;
668 
669 	dummy = rpc_broadcast_exp(prog, vers, proc, xargs, argsp,
670 		xresults, resultsp, eachresult,
671 		INITTIME, WAITTIME, nettype);
672 	return (dummy);
673 }
674