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