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