xref: /freebsd/lib/libc/rpc/clnt_bcast.c (revision 5521ff5a4d1929056e7ffc982fac3341ca54df7c)
1 /*	$NetBSD: clnt_bcast.c,v 1.3 2000/07/06 03:05:20 christos Exp $	*/
2 /*	$FreeBSD$ */
3 
4 /*
5  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
6  * unrestricted use provided that this legend is included on all tape
7  * media and as a part of the software program in whole or part.  Users
8  * may copy or modify Sun RPC without charge, but are not authorized
9  * to license or distribute it to anyone else except as part of a product or
10  * program developed by the user.
11  *
12  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
13  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
14  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
15  *
16  * Sun RPC is provided with no support and without any obligation on the
17  * part of Sun Microsystems, Inc. to assist in its use, correction,
18  * modification or enhancement.
19  *
20  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
21  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
22  * OR ANY PART THEREOF.
23  *
24  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
25  * or profits or other special, indirect and consequential damages, even if
26  * Sun has been advised of the possibility of such damages.
27  *
28  * Sun Microsystems, Inc.
29  * 2550 Garcia Avenue
30  * Mountain View, California  94043
31  */
32 /*
33  * Copyright (c) 1986-1991 by Sun Microsystems Inc.
34  */
35 
36 /* #ident	"@(#)clnt_bcast.c	1.18	94/05/03 SMI" */
37 
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 
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 __P((int, int, int, broadlist_t *));
118 void __rpc_freebroadifs __P((broadlist_t *));
119 int __rpc_broadenable __P((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 		return 0;
146 
147 	for (ifap = ifp; ifap != NULL; ifap = ifap->ifa_next) {
148 		if (ifap->ifa_addr->sa_family != af ||
149 		    !(ifap->ifa_flags & IFF_UP))
150 			continue;
151 #ifdef INET6
152 		if ((af == AF_INET6 && !(ifap->ifa_flags & IFF_MULTICAST)) ||
153 		    !(ifap->ifa_flags & IFF_BROADCAST))
154 			continue;
155 #endif
156 		bip = (struct broadif *)malloc(sizeof *bip);
157 		if (bip == NULL)
158 			break;
159 		bip->index = if_nametoindex(ifap->ifa_name);
160 #ifdef INET6
161 		if (af != AF_INET6 && (ifap->ifa_flags & IFF_BROADCAST)) {
162 #else
163 		if (ifap->ifa_flags & IFF_BROADCAST) {
164 #endif
165 			memcpy(&bip->broadaddr, ifap->ifa_broadaddr,
166 			    (size_t)ifap->ifa_broadaddr->sa_len);
167 			sin = (struct sockaddr_in *)(void *)&bip->broadaddr;
168 			sin->sin_port =
169 			    ((struct sockaddr_in *)
170 			    (void *)res->ai_addr)->sin_port;
171 #ifdef INET6
172 		} else if (af == AF_INET6) {
173 			sin6 = (struct sockaddr_in6 *)(void *)&bip->broadaddr;
174 			inet_pton(af, RPCB_MULTICAST_ADDR, &sin6->sin6_addr);
175 			sin6->sin6_family = af;
176 			sin6->sin6_len = sizeof *sin6;
177 			sin6->sin6_port =
178 			    ((struct sockaddr_in6 *)
179 			    (void *)res->ai_addr)->sin6_port;
180 			sin6->sin6_scope_id = bip->index;
181 #endif
182 		}
183 		TAILQ_INSERT_TAIL(list, bip, link);
184 		count++;
185 	}
186 	freeifaddrs(ifp);
187 	freeaddrinfo(res);
188 
189 	return count;
190 }
191 
192 void
193 __rpc_freebroadifs(broadlist_t *list)
194 {
195 	struct broadif *bip, *next;
196 
197 	bip = TAILQ_FIRST(list);
198 
199 	while (bip != NULL) {
200 		next = TAILQ_NEXT(bip, link);
201 		free(bip);
202 		bip = next;
203 	}
204 }
205 
206 int
207 /*ARGSUSED*/
208 __rpc_broadenable(int af, int s, struct broadif *bip)
209 {
210 	int o = 1;
211 
212 #if 0
213 	if (af == AF_INET6) {
214 		fprintf(stderr, "set v6 multicast if to %d\n", bip->index);
215 		if (_setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_IF, &bip->index,
216 		    sizeof bip->index) < 0)
217 			return -1;
218 	} else
219 #endif
220 		if (_setsockopt(s, SOL_SOCKET, SO_BROADCAST, &o, sizeof o) < 0)
221 			return -1;
222 
223 	return 0;
224 }
225 
226 
227 enum clnt_stat
228 rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp,
229 	eachresult, inittime, waittime, nettype)
230 	rpcprog_t	prog;		/* program number */
231 	rpcvers_t	vers;		/* version number */
232 	rpcproc_t	proc;		/* procedure number */
233 	xdrproc_t	xargs;		/* xdr routine for args */
234 	caddr_t		argsp;		/* pointer to args */
235 	xdrproc_t	xresults;	/* xdr routine for results */
236 	caddr_t		resultsp;	/* pointer to results */
237 	resultproc_t	eachresult;	/* call with each result obtained */
238 	int 		inittime;	/* how long to wait initially */
239 	int 		waittime;	/* maximum time to wait */
240 	const char		*nettype;	/* transport type */
241 {
242 	enum clnt_stat	stat = RPC_SUCCESS; /* Return status */
243 	XDR 		xdr_stream; /* XDR stream */
244 	XDR 		*xdrs = &xdr_stream;
245 	struct rpc_msg	msg;	/* RPC message */
246 	struct timeval	t;
247 	char 		*outbuf = NULL;	/* Broadcast msg buffer */
248 	char		*inbuf = NULL; /* Reply buf */
249 	int		inlen;
250 	u_int 		maxbufsize = 0;
251 	AUTH 		*sys_auth = authunix_create_default();
252 	int		i;
253 	void		*handle;
254 	char		uaddress[1024];	/* A self imposed limit */
255 	char		*uaddrp = uaddress;
256 	int 		pmap_reply_flag; /* reply recvd from PORTMAP */
257 	/* An array of all the suitable broadcast transports */
258 	struct {
259 		int fd;		/* File descriptor */
260 		int af;
261 		int proto;
262 		struct netconfig *nconf; /* Netconfig structure */
263 		u_int asize;	/* Size of the addr buf */
264 		u_int dsize;	/* Size of the data buf */
265 		struct sockaddr_storage raddr; /* Remote address */
266 		broadlist_t nal;
267 	} fdlist[MAXBCAST];
268 	struct pollfd pfd[MAXBCAST];
269 	size_t fdlistno = 0;
270 	struct r_rpcb_rmtcallargs barg;	/* Remote arguments */
271 	struct r_rpcb_rmtcallres bres; /* Remote results */
272 	size_t outlen, outlen_pmap;
273 	struct netconfig *nconf;
274 	int msec;
275 	int pollretval;
276 	int fds_found;
277 
278 #ifdef PORTMAP
279 	u_long port;		/* Remote port number */
280 	int pmap_flag = 0;	/* UDP exists ? */
281 	char *outbuf_pmap = NULL;
282 	struct rmtcallargs barg_pmap;	/* Remote arguments */
283 	struct rmtcallres bres_pmap; /* Remote results */
284 	u_int udpbufsz = 0;
285 #endif				/* PORTMAP */
286 
287 	if (sys_auth == NULL) {
288 		return (RPC_SYSTEMERROR);
289 	}
290 	/*
291 	 * initialization: create a fd, a broadcast address, and send the
292 	 * request on the broadcast transport.
293 	 * Listen on all of them and on replies, call the user supplied
294 	 * function.
295 	 */
296 
297 	if (nettype == NULL)
298 		nettype = "datagram_n";
299 	if ((handle = __rpc_setconf(nettype)) == NULL) {
300 		return (RPC_UNKNOWNPROTO);
301 	}
302 	while ((nconf = __rpc_getconf(handle)) != NULL) {
303 		int fd;
304 		struct __rpc_sockinfo si;
305 
306 		if (nconf->nc_semantics != NC_TPI_CLTS)
307 			continue;
308 		if (fdlistno >= MAXBCAST)
309 			break;	/* No more slots available */
310 		if (!__rpc_nconf2sockinfo(nconf, &si))
311 			continue;
312 
313 		TAILQ_INIT(&fdlist[fdlistno].nal);
314 		if (__rpc_getbroadifs(si.si_af, si.si_proto, si.si_socktype,
315 		    &fdlist[fdlistno].nal) == 0)
316 			continue;
317 
318 		fd = _socket(si.si_af, si.si_socktype, si.si_proto);
319 		if (fd < 0) {
320 			stat = RPC_CANTSEND;
321 			continue;
322 		}
323 		fdlist[fdlistno].af = si.si_af;
324 		fdlist[fdlistno].proto = si.si_proto;
325 		fdlist[fdlistno].fd = fd;
326 		fdlist[fdlistno].nconf = nconf;
327 		fdlist[fdlistno].asize = __rpc_get_a_size(si.si_af);
328 		pfd[fdlistno].events = POLLIN | POLLPRI |
329 			POLLRDNORM | POLLRDBAND;
330 		pfd[fdlistno].fd = fdlist[fdlistno].fd = fd;
331 		fdlist[fdlistno].dsize = __rpc_get_t_size(si.si_af, si.si_proto,
332 							  0);
333 
334 		if (maxbufsize <= fdlist[fdlistno].dsize)
335 			maxbufsize = fdlist[fdlistno].dsize;
336 
337 #ifdef PORTMAP
338 		if (si.si_af == AF_INET && si.si_proto == IPPROTO_UDP) {
339 			udpbufsz = fdlist[fdlistno].dsize;
340 			if ((outbuf_pmap = malloc(udpbufsz)) == NULL) {
341 				_close(fd);
342 				stat = RPC_SYSTEMERROR;
343 				goto done_broad;
344 			}
345 			pmap_flag = 1;
346 		}
347 #endif				/* PORTMAP */
348 		fdlistno++;
349 	}
350 
351 	if (fdlistno == 0) {
352 		if (stat == RPC_SUCCESS)
353 			stat = RPC_UNKNOWNPROTO;
354 		goto done_broad;
355 	}
356 	if (maxbufsize == 0) {
357 		if (stat == RPC_SUCCESS)
358 			stat = RPC_CANTSEND;
359 		goto done_broad;
360 	}
361 	inbuf = malloc(maxbufsize);
362 	outbuf = malloc(maxbufsize);
363 	if ((inbuf == NULL) || (outbuf == NULL)) {
364 		stat = RPC_SYSTEMERROR;
365 		goto done_broad;
366 	}
367 
368 	/* Serialize all the arguments which have to be sent */
369 	(void) gettimeofday(&t, NULL);
370 	msg.rm_xid = __RPC_GETXID(&t);
371 	msg.rm_direction = CALL;
372 	msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
373 	msg.rm_call.cb_prog = RPCBPROG;
374 	msg.rm_call.cb_vers = RPCBVERS;
375 	msg.rm_call.cb_proc = RPCBPROC_CALLIT;
376 	barg.prog = prog;
377 	barg.vers = vers;
378 	barg.proc = proc;
379 	barg.args.args_val = argsp;
380 	barg.xdr_args = xargs;
381 	bres.addr = uaddrp;
382 	bres.results.results_val = resultsp;
383 	bres.xdr_res = xresults;
384 	msg.rm_call.cb_cred = sys_auth->ah_cred;
385 	msg.rm_call.cb_verf = sys_auth->ah_verf;
386 	xdrmem_create(xdrs, outbuf, maxbufsize, XDR_ENCODE);
387 	if ((!xdr_callmsg(xdrs, &msg)) ||
388 	    (!xdr_rpcb_rmtcallargs(xdrs,
389 	    (struct rpcb_rmtcallargs *)(void *)&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 					    (size_t)fdlist[i].asize) !=
455 					    outlen) {
456 #ifdef RPC_DEBUG
457 						perror("sendto");
458 #endif
459 						warnx("clnt_bcast: cannot send"
460 						      "broadcast packet");
461 						stat = RPC_CANTSEND;
462 						continue;
463 					};
464 #ifdef RPC_DEBUG
465 				if (!__rpc_lowvers)
466 					fprintf(stderr, "Broadcast packet sent "
467 						"for %s\n",
468 						 fdlist[i].nconf->nc_netid);
469 #endif
470 #ifdef PORTMAP
471 				/*
472 				 * Send the version 2 packet also
473 				 * for UDP/IP
474 				 */
475 				if (fdlist[i].proto == IPPROTO_UDP) {
476 					if (_sendto(fdlist[i].fd, outbuf_pmap,
477 					    outlen_pmap, 0, addr,
478 					    (size_t)fdlist[i].asize) !=
479 						outlen_pmap) {
480 						warnx("clnt_bcast: "
481 						    "Cannot send broadcast packet");
482 						stat = RPC_CANTSEND;
483 						continue;
484 					}
485 				}
486 #ifdef RPC_DEBUG
487 				fprintf(stderr, "PMAP Broadcast packet "
488 					"sent for %s\n",
489 					fdlist[i].nconf->nc_netid);
490 #endif
491 #endif				/* PORTMAP */
492 			}
493 			/* End for sending all packets on this transport */
494 		}	/* End for sending on all transports */
495 
496 		if (eachresult == NULL) {
497 			stat = RPC_SUCCESS;
498 			goto done_broad;
499 		}
500 
501 		/*
502 		 * Get all the replies from these broadcast requests
503 		 */
504 	recv_again:
505 
506 		switch (pollretval = _poll(pfd, fdlistno, msec)) {
507 		case 0:		/* timed out */
508 			stat = RPC_TIMEDOUT;
509 			continue;
510 		case -1:	/* some kind of error - we ignore it */
511 			goto recv_again;
512 		}		/* end of poll results switch */
513 
514 		for (i = fds_found = 0;
515 		     i < fdlistno && fds_found < pollretval; i++) {
516 			bool_t done = FALSE;
517 
518 			if (pfd[i].revents == 0)
519 				continue;
520 			else if (pfd[i].revents & POLLNVAL) {
521 				/*
522 				 * Something bad has happened to this descri-
523 				 * ptor. We can cause _poll() to ignore
524 				 * it simply by using a negative fd.  We do that
525 				 * rather than compacting the pfd[] and fdlist[]
526 				 * arrays.
527 				 */
528 				pfd[i].fd = -1;
529 				fds_found++;
530 				continue;
531 			} else
532 				fds_found++;
533 #ifdef RPC_DEBUG
534 			fprintf(stderr, "response for %s\n",
535 				fdlist[i].nconf->nc_netid);
536 #endif
537 		try_again:
538 			inlen = _recvfrom(fdlist[i].fd, inbuf, fdlist[i].dsize,
539 			    0, (struct sockaddr *)(void *)&fdlist[i].raddr,
540 			    &fdlist[i].asize);
541 			if (inlen < 0) {
542 				if (errno == EINTR)
543 					goto try_again;
544 				warnx("clnt_bcast: Cannot receive reply to "
545 					"broadcast");
546 				stat = RPC_CANTRECV;
547 				continue;
548 			}
549 			if (inlen < sizeof (u_int32_t))
550 				continue; /* Drop that and go ahead */
551 			/*
552 			 * see if reply transaction id matches sent id.
553 			 * If so, decode the results. If return id is xid + 1
554 			 * it was a PORTMAP reply
555 			 */
556 			if (*((u_int32_t *)(void *)(inbuf)) ==
557 			    *((u_int32_t *)(void *)(outbuf))) {
558 				pmap_reply_flag = 0;
559 				msg.acpted_rply.ar_verf = _null_auth;
560 				msg.acpted_rply.ar_results.where =
561 					(caddr_t)(void *)&bres;
562 				msg.acpted_rply.ar_results.proc =
563 					(xdrproc_t)xdr_rpcb_rmtcallres;
564 #ifdef PORTMAP
565 			} else if (pmap_flag &&
566 				*((u_int32_t *)(void *)(inbuf)) ==
567 				*((u_int32_t *)(void *)(outbuf_pmap))) {
568 				pmap_reply_flag = 1;
569 				msg.acpted_rply.ar_verf = _null_auth;
570 				msg.acpted_rply.ar_results.where =
571 					(caddr_t)(void *)&bres_pmap;
572 				msg.acpted_rply.ar_results.proc =
573 					(xdrproc_t)xdr_rmtcallres;
574 #endif				/* PORTMAP */
575 			} else
576 				continue;
577 			xdrmem_create(xdrs, inbuf, (u_int)inlen, XDR_DECODE);
578 			if (xdr_replymsg(xdrs, &msg)) {
579 				if ((msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
580 				    (msg.acpted_rply.ar_stat == SUCCESS)) {
581 					struct netbuf taddr, *np;
582 					struct sockaddr_in *sin;
583 
584 #ifdef PORTMAP
585 					if (pmap_flag && pmap_reply_flag) {
586 						sin = (struct sockaddr_in *)
587 						    (void *)&fdlist[i].raddr;
588 						sin->sin_port =
589 						    htons((u_short)port);
590 						taddr.len = taddr.maxlen =
591 						    fdlist[i].raddr.ss_len;
592 						taddr.buf = &fdlist[i].raddr;
593 						done = (*eachresult)(resultsp,
594 						    &taddr, fdlist[i].nconf);
595 					} else {
596 #endif				/* PORTMAP */
597 #ifdef RPC_DEBUG
598 						fprintf(stderr, "uaddr %s\n",
599 						    uaddrp);
600 #endif
601 						np = uaddr2taddr(
602 						    fdlist[i].nconf, uaddrp);
603 						done = (*eachresult)(resultsp,
604 						    np, fdlist[i].nconf);
605 						free(np);
606 #ifdef PORTMAP
607 					}
608 #endif				/* PORTMAP */
609 				}
610 				/* otherwise, we just ignore the errors ... */
611 			}
612 			/* else some kind of deserialization problem ... */
613 
614 			xdrs->x_op = XDR_FREE;
615 			msg.acpted_rply.ar_results.proc = (xdrproc_t) xdr_void;
616 			(void) xdr_replymsg(xdrs, &msg);
617 			(void) (*xresults)(xdrs, resultsp);
618 			XDR_DESTROY(xdrs);
619 			if (done) {
620 				stat = RPC_SUCCESS;
621 				goto done_broad;
622 			} else {
623 				goto recv_again;
624 			}
625 		}		/* The recv for loop */
626 	}			/* The giant for loop */
627 
628 done_broad:
629 	if (inbuf)
630 		(void) free(inbuf);
631 	if (outbuf)
632 		(void) free(outbuf);
633 #ifdef PORTMAP
634 	if (outbuf_pmap)
635 		(void) free(outbuf_pmap);
636 #endif				/* PORTMAP */
637 	for (i = 0; i < fdlistno; i++) {
638 		(void)_close(fdlist[i].fd);
639 		__rpc_freebroadifs(&fdlist[i].nal);
640 	}
641 	AUTH_DESTROY(sys_auth);
642 	(void) __rpc_endconf(handle);
643 
644 	return (stat);
645 }
646 
647 
648 enum clnt_stat
649 rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
650 			eachresult, nettype)
651 	rpcprog_t	prog;		/* program number */
652 	rpcvers_t	vers;		/* version number */
653 	rpcproc_t	proc;		/* procedure number */
654 	xdrproc_t	xargs;		/* xdr routine for args */
655 	caddr_t		argsp;		/* pointer to args */
656 	xdrproc_t	xresults;	/* xdr routine for results */
657 	caddr_t		resultsp;	/* pointer to results */
658 	resultproc_t	eachresult;	/* call with each result obtained */
659 	const char		*nettype;	/* transport type */
660 {
661 	enum clnt_stat	dummy;
662 
663 	dummy = rpc_broadcast_exp(prog, vers, proc, xargs, argsp,
664 		xresults, resultsp, eachresult,
665 		INITTIME, WAITTIME, nettype);
666 	return (dummy);
667 }
668